/** * Raise the counter inside the thread context. * * @return void */ public function run() { // raise the counter by 1 till 5000 for ($i = 0; $i < 5000; $i++) { \Mutex::lock($this->mutex); $this->object->counter++; \Mutex::unlock($this->mutex); } }
public function run() { if ($this->mutex) { printf("LOCK(%d): %d\n", $this->getThreadId(), Mutex::lock($this->mutex)); } if ($result = mysql_query("SHOW PROCESSLIST;", $this->mysql)) { while ($row = mysql_fetch_assoc($result)) { print_r($row); } } if ($this->mutex) { printf("UNLOCK(%d): %d\n", $this->getThreadId(), Mutex::unlock($this->mutex)); } }
public function run() { if ($this->mutex) { $locked = Mutex::lock($this->mutex); } printf("%s#%lu:<-", $locked ? "Y" : "N", $this->getThreadId()); $i = 0; while ($i++ < $this->limit) { echo "."; } printf("->\n"); if ($this->mutex) { Mutex::unlock($this->mutex); } return true; }
public function run() { if ($this->mutex) { $locked = Mutex::lock($this->mutex); } $counter = shm_get_var($this->shmid, 1); $counter++; shm_put_var($this->shmid, 1, $counter); printf("Thread #%lu lock: %s says: %s\n", $this->getThreadId(), !empty($locked) ? "Y" : "N", $counter); //$this->lock(); //$this->unlock(); if ($this->mutex) { Mutex::unlock($this->mutex); } return true; }
public function run() { /* see, first lock mutex */ printf("Running(%d) %f\n", Mutex::lock($this->lock), microtime(true)); /* print some stuff to standard output */ $stdout = fopen("php://stdout", "w"); while (++$i < rand(200, 400)) { echo "."; fflush($stdout); } echo "\n"; fflush($stdout); /* and unlock mutex, making it ready for destruction */ printf("Returning(%d) %f\n", Mutex::unlock($this->lock), microtime(true)); fflush($stdout); /* you should close resources, or not, whatever; I'm not your mother ... */ return null; }
public function run() { if ($this->mutex) { $locked = Mutex::lock($this->mutex); } /* $this->synchronized(function($thread){ $thread->wait(); }, $this); */ $counter = intval(fgets($this->handle)); $counter++; //$this->lock(); //fseek($this->handle, 0); rewind($this->handle); fputs($this->handle, $counter); //fflush($this->handle); //$this->unlock(); printf("Thread #%lu says: %s\n", $this->getThreadId(), $counter); if ($this->mutex) { Mutex::unlock($this->mutex); } }
/** * Create a new timer instance with the passed data. * * @param \AppserverIo\Psr\EnterpriseBeans\TimerServiceInterface $timerService The timer service to create the service for * @param \DateTime $initialExpiration The date at which the first timeout should occur. * If the date is in the past, then the timeout is triggered immediately * when the timer moves to TimerState::ACTIVE * @param integer $intervalDuration The interval (in milli seconds) between consecutive timeouts for the newly created timer. * Cannot be a negative value. A value of 0 indicates a single timeout action * @param \Serializable $info Serializable info that will be made available through the newly created timers Timer::getInfo() method * @param boolean $persistent TRUE if the newly created timer has to be persistent * * @return \AppserverIo\Psr\EnterpriseBeans\TimerInterface Returns the newly created timer * * @throws \Exception */ public function createTimer(TimerServiceInterface $timerService, \DateTime $initialExpiration, $intervalDuration = 0, \Serializable $info = null, $persistent = true) { // lock the method \Mutex::lock($this->mutex); // we're not dispatched $this->dispatched = false; // initialize the data $this->info = $info; $this->persistent = $persistent; $this->timerService = $timerService; $this->intervalDuration = $intervalDuration; $this->initialExpiration = $initialExpiration->format(ScheduleExpression::DATE_FORMAT); // notify the thread $this->notify(); // wait till we've dispatched the request while ($this->dispatched === false) { usleep(100); } // unlock the method \Mutex::unlock($this->mutex); // return the created timer return $this->timer; }
$r = sqrt($imw * $imh * $percent / ($watermark_width * $watermark_height)); if (!getOption('watermark_allow_upscale')) { $r = min(1, $r); } $nw = round($watermark_width * $r); $nh = round($watermark_height * $r); if ($nw != $watermark_width || $nh != $watermark_height) { $watermark = zp_imageResizeAlpha($watermark, $nw, $nh); } // Position Overlay in Bottom Right $dest_x = max(0, floor(($imw - $nw) * $offset_w)); $dest_y = max(0, floor(($imh - $nh) * $offset_h)); zp_copyCanvas($newim, $watermark, $dest_x, $dest_y, 0, 0, $nw, $nh); zp_imageKill($watermark); } $iMutex->unlock(); if (!zp_imageOutput($newim, $suffix, $cache_path, $quality) && DEBUG_IMAGE) { debugLog('full-image failed to create:' . $image); } } } if (!is_null($cache_path)) { if ($disposal == 'Download' || !OPEN_IMAGE_CACHE) { require_once dirname(__FILE__) . '/lib-MimeTypes.php'; $mimetype = getMimeString($suffix); $fp = fopen($cache_path, 'rb'); // send the right headers header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header("Content-Type: {$mimetype}"); header("Content-Length: " . filesize($image_path)); // dump the picture and stop the script
/** * Create a calendar-based timer based on the input schedule expression. * * @param \AppserverIo\Psr\EnterpriseBeans\TimerServiceInterface $timerService The timer service to create the service for * @param \AppserverIo\Psr\EnterpriseBeans\ScheduleExpression $schedule A schedule expression describing the timeouts for this timer * @param \Serializable $info Serializable info that will be made available through the newly created timers Timer::getInfo() method * @param boolean $persistent TRUE if the newly created timer has to be persistent * @param \AppserverIo\Lang\Reflection\MethodInterface $timeoutMethod The timeout method to be invoked * * @return \AppserverIo\Psr\EnterpriseBeans\TimerInterface The newly created Timer. * @throws \AppserverIo\Psr\EnterpriseBeans\EnterpriseBeansException If this method could not complete due to a system-level failure. * @throws \Exception */ public function createTimer(TimerServiceInterface $timerService, ScheduleExpression $schedule, \Serializable $info = null, $persistent = true, MethodInterface $timeoutMethod = null) { // lock the method \Mutex::lock($this->mutex); // we're not dispatched $this->dispatched = false; // initialize the data $this->info = $info; $this->schedule = $schedule; $this->persistent = $persistent; $this->timerService = $timerService; $this->timeoutMethod = $timeoutMethod; // notify the thread $this->notify(); // wait till we've dispatched the request while ($this->dispatched === false) { usleep(100); } // unlock the method \Mutex::unlock($this->mutex); // return the created timer return $this->timer; }
/** * Create a new instance with the passed data. * * @param string $className The fully qualified class name to return the instance for * @param string|null $sessionId The session-ID, necessary to inject stateful session beans (SFBs) * @param array $args Arguments to pass to the constructor of the instance * * @return object The instance itself * * @throws \Exception */ public function newInstance($className, $sessionId = null, array $args = array()) { // lock the method \Mutex::lock($this->mutex); // we're not dispatched $this->dispatched = false; // initialize the data $this->args = $args; $this->sessionId = $sessionId; $this->className = $className; // notify the thread $this->notify(); // wait till we've dispatched the request while ($this->dispatched === false) { usleep(100); } // try to load the last created instance if (isset($this->instances[$last = sizeof($this->instances) - 1])) { $instance = $this->instances[$last]; } else { throw new \Exception('Requested instance can\'t be created'); } // unlock the method \Mutex::unlock($this->mutex); // return the created instance return $instance; }
/** * 释放写锁 * @return true */ public static function release() { \Mutex::unlock(self::getSemFd()); }
<?php require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '../lib/Mutex/Mutex.class.php'; $m = new Mutex('allo'); echo $m->getMutexType(); $fiction = true; if ($fiction === false) { $x = new Mutex('allo'); $x->lock(); echo "Yay"; $x->unlock(); } $m->lock(); echo "locked"; $m->unlock(); echo "unlocked"; unset($m);
/** * Handles the request processing. * * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface $servletRequest The actual request instance * @param \AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface $servletResponse The actual response instance * * @return void * * @throws \Exception */ public function handleRequest(HttpServletRequestInterface $servletRequest, HttpServletResponseInterface $servletResponse) { // lock the method \Mutex::lock($this->mutex); do { // create a counter $counter = 0; // if this is the first loop if ($counter === 0) { // we're not dispatched $this->dispatched = false; // synchronize request/response $this->servletRequest = $servletRequest; $this->servletResponse = $servletResponse; // notify the thread $this->synchronized(function ($self) { $self->notify(); }, $this); } // raise the counter $counter++; // we wait for 100 iterations if ($counter > 100) { throw new \Exception('Can\'t handle request'); } // lower system load a bit usleep(100); } while ($this->dispatched === false); // unlock the method \Mutex::unlock($this->mutex); }
/** * Release generic per-record mutex lock */ public function atomicEnd($label) { if (!$this->exists($label)) { self::$log->error("Trying to release Mutex for a record whose label does not exist"); return false; } $m = new Mutex($this->label2key($this->getContext() . $label)); $m->unlock(); return true; }