|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #36541 Block-level Semaphore Locking
Submitted: 2006-02-27 11:00 UTC Modified: 2016-12-30 23:35 UTC
Avg. Score:4.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: zabmilenko at charter dot net Assigned:
Status: Open Package: Semaphore related
PHP Version: 5.1.2 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: zabmilenko at charter dot net
New email:
PHP Version: OS:


 [2006-02-27 11:00 UTC] zabmilenko at charter dot net
Currently, the sysvsem library is used for semaphore locking.  I am proposing to integrate this functionality directly into php using a block-level statement:

sem (420)
   // Locked stuff here

The idea is that any code present inside the sem{} block will be guaranteed by php to be executed alone.  420 is the lock to set or wait for.  Execution can be halted before the end of the sem block using the break; statement, as well as return, die, exit, or any other statement that moves execution outside of the block.  As soon as execution leaves, the semaphore is instantly released.

Naturally, nesting a lock is redundant but nevertheless could serve a purpose.  If a nested lock is detected, a warning should be generated.

This functionality would be minimalistic, but powerful and elegant when compared to the sysvsem library.  If your imagination is wandering, then a radical idea would be setting a timeout or even a lock-count limit using parameters separated by ; (like a for() block).

Anyways, my suggestion is a sem block.  Have a nice day.

Reproduce code:
sem (0x2243)
   // open a file
   // write a line
   // close the file

Expected result:
The first process will lock semaphore 0x2243 and attempt to write a line to a file.  Any concurrent attempts will be delayed until the first process reaches leaves the sem block.

Actual result:
I get a parse error because my idea is still only in my head.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-01 14:30 UTC] zabmilenko at charter dot net
Changing the OS to ALL, because that makes more sense.
 [2006-09-05 06:19 UTC] zabmilenko at charter dot net
I do not know much about how declare() works, but I believe it could be expanded like so:

   // blahblah

Since declare() seems to block up code with some timer running (via ticks?), a small part of the work could be finished already.
 [2016-12-30 23:35 UTC]
-Package: Feature/Change Request +Package: Semaphore related
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 16 10:01:28 2024 UTC