Exemple #1
0
 /**
  * Attempt to lock the Mutex for the caller.
  *
  * An attempt to lock a Mutex owned (locked) by another Thread will result in blocking.
  *
  * @param int $mutex A handle returned by a previous call to Mutex::create().
  *
  * @link http://www.php.net/manual/en/mutex.lock.php
  * @return bool A boolean indication of success
  */
 public static function lock($mutex)
 {
     if (fhread_mutex_lock($mutex) === 0) {
         return true;
     }
     return false;
 }
Exemple #2
0
 public function run()
 {
     // lock data object
     fhread_mutex_lock($this->data->mutex);
     // inc counter
     ++$this->data->counter;
     // add message that this thread was here
     $this->data->objects[$this->getThreadId()] = new stdClass();
     // unlock data object
     fhread_mutex_unlock($this->data->mutex);
 }
Exemple #3
0
 /**
  * Executes given closure synchronized
  *
  * @param callable $sync
  */
 public function synchronized(\Closure $sync)
 {
     fhread_mutex_lock($this->syncMutex);
     $sync->__invoke($this);
     fhread_mutex_unlock($this->syncMutex);
 }