ID:               41805
 Updated by:       [EMAIL PROTECTED]
 Reported By:      ein at anti-logic dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Filesystem function related
 Operating System: linux 2.6
 PHP Version:      4.4.7
 New Comment:

>$fp = sem_get(fileinode('lock_file', 100, 666); 
Why would it block if you set max_acquire to 100.
Change it to 1 and it will block.


Previous Comments:
------------------------------------------------------------------------

[2007-06-25 18:20:30] ein at anti-logic dot com

Description:
------------
It is impossible to duplicate flock functionality with the sem controls
due to sem_get's and sem_aquire's inability to ensure exclusive access.

For example with flock, if we create a non exclusive (shared) lock,
followed by an exclusive lock, it will block on the second lock
creation. This is the expected behaviour, and allows us to ensure that
there is exclusive access to the file.

Reproduce code:
---------------
$fp = sem_get(fileinode('lock_file', 100, 666);
sem_acquire($fp);
echo "one lock is in place, we should Block on the second lock
request";
$fp2 = sem_get(fileinode('lock_file', 1, 666);
sem_acquire($fp2);
echo "but we have not";

$fp3 = fopen('lock_file', 'w');
flock($fp3, LOCK_SH);
echo "one flock is in place, we should block on the next lock
request";
$fp4 = fopen('lock_file', 'w');
flock($fp4, LOCK_EX);
echo "we will never see this text due to proper indefinite blocking";

Expected result:
----------------
sem_aquire should block on the second lock creation.

Actual result:
--------------
It will not block, nor will sem_get or sem_aquire return an error.

I believe the confusion may be caused by this line in the
documentation, "Actually this value is set only if the process finds it
is the only process currently attached to the semaphore."  However, that
is reffering only to the perm field, and not max_aquire.  Either the
documentation should be updated to reflect the (broken) implementation,
or the sem_aquire/sem_get functions should be modified to ensure an
exclusive lock request (max_aquire=1) will block when an existing lock
is in place.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=41805&edit=1

Reply via email to