小编zek*_*868的帖子

PHP/pthreads Thread类不能使用数组?

我发现PECL pthread Thread不能使用数组对象.我该怎么做才能找到原因?

代码示例:

   class my extends Thread {

           public function __construct() {
                   $this->arr = array();
                   $this->id  = 0;
           }
           public function run() {
                   while (true) {
                           $this->wait();
                   }
           }

           public function add() {
                   $this->id = rand(0, 1000);
                   $this->arr[] = rand(0, 1000);
                   var_dump($this->id);//this is rand
                   var_dump($this->arr);//this is empty array()
                   $this->notify();
           }
   }

   $my = new my();
   $my->start();
   while (true) {
           sleep(1);
           $my->add();
   } 
Run Code Online (Sandbox Code Playgroud)

php multithreading pthreads

12
推荐指数
1
解决办法
8049
查看次数

标签 统计

multithreading ×1

php ×1

pthreads ×1