tpunt / pht

A new threading extension for PHP
BSD 3-Clause "New" or "Revised" License
179 stars 14 forks source link

no-joined thread leads to high cpu usage #7

Closed zhaoyanliang2 closed 5 years ago

zhaoyanliang2 commented 5 years ago

If the parent thread forget to join the child thread, or too busy to join (and child thread finish task quickly), or even does not plan to join, then, the child thread leads to high cpu usage.

<?php
use pht\Thread;

$thread = new Thread;
$thread->addFunctionTask('task');
$thread->start();
sleep(10000);

function task()
{
    sleep(1);
}

I debugged it and found it here. https://github.com/tpunt/pht/blob/d79019cf96d0ff0f7389382148ef6ffc70b761e8/src/classes/thread.c#L278 After the child thread has executed all the tasks, it will cause this problem if it has not been joined yet.

By the way, are you still going to continue to maintain this project? @tpunt

tpunt commented 5 years ago

This is a known issue (#6) - I just haven't had the time to resolve it yet.

As for the future of this project, that is currently unknown. There's some issues with this extension, and I don't have the time to look into resolving them currently. Perhaps you should look into parallel for your multithreading needs? It looks like Joe has done a pretty good job on it so far, and he is actively developing it too.