pthreads
pthreads copied to clipboard
Permit overriding join() to intercept thread shutdowns triggered by pthreads itself
Environment
- PHP: 7.2.13
- pthreads: 5eb80c0c691aa81e0d235bdd37f6f30b633c433e
- OS: w10 x64
Summary
I would like to be able to have my custom join() function called when the thread context tries to be destroyed. Currently this isn't possible because pthreads_join is called directly, without giving the user chance to react to it.
Reproducing Code
$t = new class extends \Thread{
private $shutdown = false;
public function run(){
$this->synchronized(function(){
while(!$this->shutdown){
$this->wait();
}
});
}
public function join(){
$this->synchronized(function(){
$this->shutdown = true;
$this->notify();
});
}
};
$t->start();
unset($t);
die("OK");
Desired output
OK
Actual Output
Nothing - the script just hangs at the unset() call as pthreads tries to fruitlessly join it.