PHP - Threaded::synchronized() Function
Threaded::synchronized - Synchronization
Syntax
public mixed Threaded::synchronized( Closure $block [, mixed $... ] )
Threaded::synchronized() function can execute the block while retaining a referenced objects synchronization lock for the calling context.
Threaded:: synchronized() function can return a value from the block.
Example
<?php
class My extends Thread {
public function run() {
$this->synchronized(function($thread) {
if(!$thread->done)
$thread->wait();
}, $this);
}
}
$my = new My();
$my->start();
$my->synchronized(function($thread) {
$thread->done = true;
$thread->notify();
}, $my);
var_dump($my->join());
?>
php_function_reference.htm
Advertisements