Note that this extension *is* a high level implementation of POSIX threads, including on Windows (which is why pthreadsV*.dll is required)
Note that this extension *is* a high level implementation of POSIX threads, including on Windows (which is why pthreadsV*.dll is required)
Hello,
WARNING : When using Stackable objects in callable functions by your Threads, you must be very careful if you use it as an array. Indeed, if you do not copy your Stackable "array" in a local variable, the execution time can drop drastically !
Also, if you want to modify an array() in a function, you will also store in a local variable in order that your array is in a thread-safe context.
If you try to test threading, remember to let php think slow:
Skript: -- C:\Webserver\htdocs>php mttest.php
<?php
class My extends Thread{
function run(){
for($i=1;$i<10;$i++){
echo Thread::getCurrentThreadId() . "\n";
sleep(2); // <------
}
}
}
for($i=0;$i<2;$i++){
$pool[] = new My();
}
foreach($pool as $worker){
$worker->start();
}
foreach($pool as $worker){
$worker->join();
}
?>
Output: -- C:\Webserver\htdocs>php mttest.php
6300
5816
6300
5816
6300
5816
6300
5816
6300
5816
6300
5816
6300
5816
6300
5816
6300
5816
If you leave sleep() out, the cpu-time for the threads is long enough to complete the script at once.