php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16986 semaphore autorelease can be a bug....
Submitted: 2002-05-03 05:37 UTC Modified: 2002-05-17 08:37 UTC
Votes:17
Avg. Score:4.4 ± 0.9
Reproduced:15 of 15 (100.0%)
Same Version:7 (46.7%)
Same OS:8 (53.3%)
From: AlberT at SuperAlberT dot it Assigned:
Status: Closed Package: Semaphore related
PHP Version: 4.1.2 OS: Linux 2.4.18
Private report: No CVE-ID: None
 [2002-05-03 05:37 UTC] AlberT at SuperAlberT dot it
sem_acquire() function has this behavior:

After processing a request, any semaphores acquired by the process but
not explicitly released will be released automatically and a warning
will be generated. 

This is not a great thing, infact in this way the readers/writers
classical IPC problem, with writers precedence is impossible to
implement !!!

I think an option to disable autorelease is usefull.

(I sent a feature/change request, but I had no feadback :-( )

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-05-03 06:47 UTC] wez@php.net
But a process that acquires a semaphore and then exits will
case deadlocks, because no one else can acquire the semaphore??
Can you give a good example of where leaving the semaphore acquired is actually useful?
 [2002-05-06 10:23 UTC] AlberT at SuperAlberT dot it
It cause deadlock, but only on the script... if you test your script
and have a deadlock, you fix it and release the sem you forgot.

I think the auto release may be a good DEFAULT, but it is important to be able to modify this behaviour.
If you want to fulfill any classical IPC problem (see Tanenbuam!)
You have to be able to acquire a sem, and not to realease it.

Here you ca nfind an explanation of the problems one can have and that
auto release make impossible to solve:

  http://joda.cis.temple.edu/~ingargio/old/cis307f95/readings/readwriters.html
 [2002-05-06 10:44 UTC] michel at ziobudda dot net
Hi, I'm the coordinator of Italian Linux Portal and just last saturday (04/05/2002 in european date) I have talked about PHP in a Linux Event. I think that the rigth "position" is the position of AlberT: If a script die and it "has" the semaphore is corret that another scripts can get that semaphore.

my 0,02euro
 [2002-05-07 10:58 UTC] AlberT at SuperAlberT dot it
Some people write me for explanations.....

ok I'll be more clear I hope:

READER:
                p(mutex);
                readcount++;
                if (readcount is 1) then p(db);
                v(mutex);
                CRITICAL REGION where we read
                p(mutex);
                readcount--;
                if (readcount  is 0) then v(db);
                v(mutex);
        WRITER:
                p(db);
                CRITICAL REGION where we write
                v(db);

this is the simplest r/w problem, ok ?!?

let we analize it now.
we have to acquire some mutex to protect owr access to variables readcount ok
??
This is possible in PHP! .. ok !

now, I'm the 1st reader .. I acquire sem DB becouse readcount is equal to 1,
I release mutex and begin to READ

NOW IT IS possible that an other reader arrive and it is faster than me; it
DON'T  acquire DB becouse readcont is now 2, it READS and DOESN'T HAVE to
release sem DB becouse readcount IS NOT 1 (reader 1  is still reading !!)...

PHP AUTORELEASE DB ... damn !!!
 [2002-05-17 08:37 UTC] wez@php.net
The new proto for sem_get is:
proto int sem_get(int key [, int max_acquire [, int perm [, int
auto_release]])

auto_release defaults to true so original behaviour is preserved; you may specify false to override.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 15:01:30 2024 UTC