pthreads icon indicating copy to clipboard operation
pthreads copied to clipboard

Stack overflow on thread start when recursive static array references are present

Open dktapps opened this issue 7 years ago • 1 comments

Environment

  • PHP: 7.2.8
  • pthreads: master
  • OS: win10 x64

Reproducing Code

class Test{
	public static $array = [];

	public static function init(){
		$ref =&self::$array;
		self::$array[] = $ref;
	}
}

Test::init();

$thread = new Worker;
$thread->start(PTHREADS_INHERIT_CLASSES);
var_dump("good");

Expected Output

string(4) "good"

Actual Output

Stack overflow

dktapps avatar Aug 03 '18 16:08 dktapps

This will overflow with the code in the statics branch also ... what you want is to have a hashtable of copied hashtables per context, what I would suggest is that you introduce a context structure passed around while preparing the thread, keep in that the table of copied tables and don't copy a table more than once .... that will solve the problem ...

krakjoe avatar Jan 15 '19 18:01 krakjoe