ID:               41805
 User updated by:  ein at anti-logic dot com
 Reported By:      ein at anti-logic dot com
 Status:           Bogus
 Bug Type:         Filesystem function related
 Operating System: linux 2.6
 PHP Version:      4.4.7
 New Comment:

I understand how max_aquire works, but as per my example above,
max_aquire=100 is providing a similiar result as flock with LOCK_SH. 
Therefore, the second sem_aquire should block with max_aquire=1 (on the
second sem_get request), just as flock with LOCK_EX does.

Have you tried the example code?


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

[2007-06-25 18:45:11] [EMAIL PROTECTED]

http://php.net/sem_get

--
max_acquire

The number of processes that can acquire the semaphore simultaneously
is set to max_acquire (defaults to 1).
--



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

[2007-06-25 18:42:51] ein at anti-logic dot com

The second lock is attempting to aquire EXCLUSIVE ACCESS.  There is not
way to ensure that another process is not using the file ahead of time. 
max_aquire=1 is synonymous with LOCK_EX as far as I am concerned.

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

[2007-06-25 18:37:02] [EMAIL PROTECTED]

>$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.

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

[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