Jump to content

Recommended Posts

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  :)

Link to comment
https://forums.phpfreaks.com/topic/58983-building-semaphores-in-php/
Share on other sites

  • 2 months later...

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++;
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.