/** * Waits for executing thread to return. * @param bool $useBlocking If is set to true will block the until the thread returns. * @return bool True if the thread has joined otherwise false. */ public final function join($useBlocking = true) { // {{{ if (!$this->amIStarted) { return false; } if ($this->amIParent()) { $status = null; $res = 0; if ($useBlocking) { GPhpThread::BGN_HIGH_PRIOR_EXEC_BLOCK(); while (($res = pcntl_waitpid($this->childPid, $status, WNOHANG)) == 0) { GPhpThreadCriticalSection::dispatch(); usleep(mt_rand(10000, 40000)); } if ($res > 0 && pcntl_wifexited($status)) { $this->exitCode = pcntl_wexitstatus($status); } else { $this->exitCode = false; } if ($this->criticalSection !== null) { $this->criticalSection->finalize($this->uniqueId); } $this->childPid = null; $this->_childPid = null; $this->amIStarted = false; GPhpThread::END_HIGH_PRIOR_EXEC_BLOCK(); } else { $res = pcntl_waitpid($this->childPid, $status, WNOHANG); if ($res > 0 && $this->criticalSection !== null) { $this->criticalSection->finalize($this->uniqueId); } if ($res > 0 && pcntl_wifexited($status)) { $this->exitCode = pcntl_wexitstatus($status); if ($this->criticalSection !== null) { $this->criticalSection->finalize($this->uniqueId); } $this->amIStarted = false; } else { if ($res == -1) { $this->exitCode = false; } } if ($res != 0) { if ($this->criticalSection !== null) { $this->criticalSection->finalize($this->uniqueId); } $this->childPid = null; $this->_childPid = null; } } return $res; } if ($this->childPid == -1) { return false; } exit(255); }