重用工作线程pthreads

时间:2014-03-23 14:30:01

标签: php multithreading pthreads

我遇到了pthread的情况。请考虑以下脚本:

<?php
class W extends \Worker {
    public function run()
    {
    echo "worker started\n";
    }
}
clasds S extends \Stackable {
    public function run()
    {
    echo "stackable executed\n";
    }
}
class x{
    protected $workers;
    protected $i;
    public function __construct()
    {
    $this->workers = array();
    $this->i = 0;
    }

    public function go()
    {
    $thread = $this->spawn();
    $j = new S;
    $thread->stack($j);
    //$thread->shutdown();
    }

    public function spawn()
    {
    $this->i !== 0 ? $n=$this->i++ : $n=$this->i;
    $thread = new W;
    $this->workers[$n] = $thread;
    $thread->start();
    return $thread; 
    }
}
$exe = new x;
$exe->go();

php崩溃。解决问题的方法有: 取消注释     $ W-&gt;关闭(); 这意味着一个人创造的工人不可重复使用或评论     $ this-&gt; c [$ n] = $ w; 这意味着不能在数组中保存worker。 我不明白这里发生了什么。一个工作人员必须关闭一个叫什么?为什么试图存储 阵列中的工作人员导致崩溃?

0 个答案:

没有答案