コード例 #1
0
ファイル: Pooling.php プロジェクト: marcosrachid/pthreads
    /*
     * If logging were allowed to occur without synchronizing
     *	the output would be illegible
     */
    public function log($message, ...$args)
    {
        $this->synchronized(function ($message, ...$args) {
            if (is_callable($message)) {
                $message(...$args);
            } else {
                echo vsprintf("{$message}\n", ...$args);
            }
        }, $message, $args);
    }
}
$logger = new SafeLog();
/*
* Constructing the Pool does not create any Threads
*/
$pool = new Pool(8, 'WebWorker', [$logger, ["sqlite:example.db"]]);
/*
* Only when there is work to do are threads created
*/
$pool->submit(new WebWork());
$pool->submit(new WebWork());
$pool->submit(new WebWork());
$pool->submit(new WebWork());
$pool->submit(new WebWork());
$pool->submit(new WebWork());
$pool->submit(new WebWork());
$pool->submit(new WebWork());
コード例 #2
0
ファイル: threads.php プロジェクト: Frozen-Shadow/EarthPic
    /*
     * If logging were allowed to occur without synchronizing
     *	the output would be illegible
     */
    public function log($message, ...$args)
    {
        $this->synchronized(function ($message, ...$args) {
            if (is_callable($message)) {
                $message(...$args);
            } else {
                echo vsprintf("{$message}\n", ...$args);
            }
        }, $message, $args);
    }
}
$logger = new SafeLog();
/*
* Constructing the Pool does not create any Threads
*/
$pool = new Pool(3, 'WebWorker', [$logger, ["sqlite:example.db"]]);
/*
* Only when there is work to do are threads created
*/
for ($i; $i < 100; $i++) {
    $pool->submit(new WebWork($i));
}
/*
* The Workers in the Pool retain references to the WebWork objects submitted
* in order to release that memory the Pool::collect method must be invoked in the same
* context that created the Pool.
*