in reply to Re: release threads resources?
in thread release threads resources?
The problem with join is that there is no equivalent to the WNOHANG parameter of waitpid, so you cannot join threads as they terminate. Rather, you have to join them in some order and if the first thread handle you attempt to join is the last to finish, all the others remain consuming process resources until it terminates.
For start-run-die-start another style algorithms, as are common with forking servers, it makes it difficult to control resource consumption by limiting the number of concurrent threads to some fixed maximum by only starting the next thread when one terminates. That's why I tend to detach the threads and use a shared var to track how many are still running, but if you need to retrieve their return values, you're stuck.
That said, Perl's threads are sufficiently heavyweight that using a long running pool of looping threads that take new work items from a queue is generally a better option anyway, but the absence of a non-blocking join is a pain for some things.
|
|---|