|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-11-07 12:23 UTC] vadim at unvsoft dot com
Description:
------------
OS: win8 PHP 5.5.5 pthread 0.45 spidermonkey 1.0.0
when thread finish work php process dies without any messages. If i disable spidermonkey extension all works fine.
Test script:
---------------
class MyThread extends Thread {
private $name;
function __construct($name) {
$this->name = $name;
}
function run() {
$res = pow(mt_rand(), mt_rand());
printf("Thread: %s (%s)\n", $this->name, uniqid());
flush();
sleep(1);
}
}
$threads_max = 10;
$threads = array();
for ($i = 0; $i < $threads_max; $i++) {
printf("Creating thread: %s\n", $i);
$threads[$i] = new MyThread("Thread " . $i);
}
foreach ($threads as $thread) $thread->start();
Expected result:
----------------
normal finish of script
Actual result:
--------------
message from windows that script died
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 22:00:01 2025 UTC |
Your threads are not being joined, zend is attempting to destroy them while they are still executing: class MyThread extends Thread { private $name; function __construct($name) { $this->name = $name; } function run() { $res = pow(mt_rand(), mt_rand()); printf("Thread: %s (%s)\n", $this->name, uniqid()); flush(); sleep(1); } } $threads_max = 10; $threads = array(); for ($i = 0; $i < $threads_max; $i++) { printf("Creating thread: %s\n", $i); $threads[$i] = new MyThread("Thread " . $i); } foreach ($threads as $thread) $thread->start(); foreach ($threads as $thread) $thread->join(); sleep() is not intended for use in multi-threaded applications, it is intended to make processes sleep, use usleep if you must have threads sleep, or else use synchronization facilities provided.