public function removeTerminated()
    {
        // @TODO: remove
        $n = 0;
        foreach ($this->threads as $id => $thread) {
            if (!$thread->getPid() || !$thread->ifExists()) {
                $thread->setTerminated();
                unset($this->threads[$id]);
                continue;
            }
            ++$n;
        }
        return $n;
    }