0

I develop a cli thread with pthread but I have a problem:

My code bellow:

class workerThread extends Thread {

private $time;

public function __construct($i) {
    $this->i = $i;
    $this->time = time();

}

public function run() {
    echo "Begin running...\n";
    while (true) {
        echo "[{$this->getThreadId()} : {$this->i}] ";
        if ($this->time + 10 < time()) {
            break;
        }
        usleep(1000000);
    }
}
}

class AppTest_Controller_Main extends Core_Controller {

    public function thread3Action() {
        error_reporting(E_ALL);
        echo "Start\n";
        $worker = new workerThread(1024);
        $worker->start();
    }
}

run cli command on centos 6.5, php v5.5.33 zts with ptheads extension

php cli.php -r"AppTest/Main/thread3"

result

Segmentation fault

But I run test thread on a file outside MVC then it work And this code work in windows.

Please help me, thank all !

Machavity
  • 30,841
  • 27
  • 92
  • 100
  • On leaving `thread3Action` `$worker` is destroyed, but it is not joined ... `join` what you `start` gracefully ... or else you will attempt to destroy executing threads ... – Joe Watkins Jan 20 '17 at 21:44
  • Possible duplicate of [Why Do I Get This Segmentation Fault In This PHP Command Line Script?](http://stackoverflow.com/questions/1106166/why-do-i-get-this-segmentation-fault-in-this-php-command-line-script) http://stackoverflow.com/questions/13079513/how-do-i-diagnose-this-php-segmentation-fault – zod Jan 20 '17 at 21:53

0 Answers0