shutdown() public method

Shuts down the Worker after executing all the threaded tasks previously stacked
public shutdown ( ) : boolean
return boolean A boolean indication of success
コード例 #1
0
ファイル: WorkerTest.php プロジェクト: stof/pthreads-polyfill
 public function testWorkerStack()
 {
     $worker = new Worker();
     $work = new WorkerTestWork();
     $worker->start();
     $worker->stack($work);
     $worker->shutdown();
     $this->assertEquals($work->hasWorker, true);
 }
コード例 #2
0
ファイル: Runner.php プロジェクト: olivier1980/alpharpc
 /**
  * Stops this Worker.
  *
  * @param integer $signal [OPTIONAL] Contains the signal in the case of a PCNTL signal.
  */
 public function stop($signal = null)
 {
     if (!$this->running) {
         return;
     }
     if (null !== $signal) {
         $this->getLogger()->info('Stop called because of signal #' . $signal . '. Current state: ' . $this->worker->getState() . '.');
     } else {
         $this->getLogger()->info('Stop called: ' . $this->worker->getState() . '.');
     }
     $this->running = false;
     $this->worker->shutdown();
 }
コード例 #3
0
 public function testWorkerGc()
 {
     $worker = new Worker();
     $work = new WorkerTestWork();
     $worker->start();
     $worker->stack($work);
     $worker->shutdown();
     $this->assertEquals(1, $worker->collect(function ($task) {
         return false;
     }));
     $this->assertEquals(0, $worker->collect(function ($task) {
         return $task->isGarbage();
     }));
 }
コード例 #4
0
ファイル: index.php プロジェクト: alexeylatypov/pi
    for ($i = 0; $i <= $n; $i++) {
        $x = lcg_value() * 2 - 1;
        $y = lcg_value() * 2 - 1;
        if ($x ** 2 + $y ** 2 <= 1) {
            $np++;
        }
    }
    return $np;
};
/* make call in background thread */
$argv = [$interation / $threads];
$time_start = microtime(true);
$np_result = 0;
// Initialize and start the threads
$worker = new Worker();
$work = array();
$o = 0;
while (++$o < $threads) {
    /* items stacked could be using resources available in worker */
    $work[] = new ParallelThread($closure, $argv);
}
foreach ($work as $w) {
    $worker->stack($w);
}
$worker->start();
//$pi = 4 * $np_result / ($argv[0]*($threads));
//echo $np_result."<br>";
//echo $pi."<br>";
echo microtime(true) - $time_start;
$worker->shutdown();