pthreads
pthreads copied to clipboard
Stack overflow on thread start when recursive static array references are present
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
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 ...