Richard Bowser Posted July 8, 2007 Share Posted July 8, 2007 A semaphore is a protected variable that embodies the classic way to restrict data access to shared resources in a multiprogramming environment. The numerical value of a semaphore represents the number of resource units available. In the special case where there is only one single item to protect, it is represented by a binary semaphore. PHP provides resources to implement System V IPC facilities, including semaphores, documented in CXXXVI. However, these won't work for me, since semaphores must be specifically enabled when PHP is compiled, and my WAMP distribution (5.1.7.2) does not include that functionality. I can implement my own semaphores, BUT I need some advice: I know a construct such as $sem = --$sem will approximate the single uninterruptible operation the interlocking primitive requires. However I will need to see actual assembly code to verify the execution sequence invoked. I need to confirm that I can get an uninterruptible test & set instruction sequence. Given that, the rest of building all needed control structures becomes almost trivially simple. Can anybody help me understand how (or even IF) I can confirm the actual code executed? Thanks in advance. Richard Bowser Quote Link to comment https://forums.phpfreaks.com/topic/58983-building-semaphores-in-php/ Share on other sites More sharing options...
btherl Posted September 19, 2007 Share Posted September 19, 2007 The relevant code is in Zend/zend_operator.c, in the function increment_function(). Assuming you're using a long for the semaphore, the code from php 5.1.6 looks like this: if (op1->value.lval == LONG_MAX) { /* switch to double */ double d = (double)op1->value.lval; ZVAL_DOUBLE(op1, d+1); } else { op1->value.lval++; } Quote Link to comment https://forums.phpfreaks.com/topic/58983-building-semaphores-in-php/#findComment-350832 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.