Skip to content
This repository has been archived by the owner on Dec 16, 2019. It is now read-only.

Permit overriding join() to intercept thread shutdowns triggered by pthreads itself #919

Open
dktapps opened this issue Jan 29, 2019 · 0 comments

Comments

@dktapps
Copy link
Contributor

dktapps commented Jan 29, 2019

Environment

  • PHP: 7.2.13
  • pthreads: 5eb80c0
  • 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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant