pmmp / ext-pmmpthread

Fork of https://github.com/krakjoe/pthreads with a revamped API and PHP 8.1+ support
Other
81 stars 17 forks source link

Worker::collect() does not account for currently running tasks #82

Closed dktapps closed 1 year ago

dktapps commented 1 year ago

This was introduced due to refactors in 5.0.0.

Neither the GC queue nor the pending tasks queue contains the currently running task when collect() is called, causing it to return 0. In a loop like this:

while($worker->collect(function(ThreadedRunnable $work) : void{
    //do something...
}) > 0);

the loop may exit early while there is a task still to be collected, since it doesn't account for the currnetly-running task.