Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^4: using many threads and conserving stack size

by danmcb (Monk)
on Nov 12, 2008 at 16:04 UTC ( [id://723199]=note: print w/replies, xml ) Need Help??


in reply to Re^3: using many threads and conserving stack size
in thread using many threads and conserving stack size

thanks. seems a bit odd, I don't see why it has to work like this. It ought to be trivial to run the script until all threads are ended, without clogging memory

In the end I just made a threadless version with a very simple scheduler, it took me about an hour to change it and it works perfectly on almost 0 resources

  • Comment on Re^4: using many threads and conserving stack size

Replies are listed 'Best First'.
Re^5: using many threads and conserving stack size
by gone2015 (Deacon) on Nov 12, 2008 at 16:26 UTC

    I believe what's going on here is that each thread, once it has finished, has a "return" value in its hot little hands.

    If you detach the thread, you've said you don't want the "return" value, so as soon as it's finished, the thread can tidy up after itself and leave the building.

    Otherwise, until you join (or detach) the thread, it's sitting there, waiting patiently to give its final report, before it tidies up and leaves. (Kind of sad, really, given how much you care !)

      yes, that makes sense. Awwww, now I have thread-guilt!

      What doesn't make sense is that if you detach a thread, it gets stomped on when the main thread ends. AFAIK there is no way to say "I don't care what value it returns, but I DO want it to actually get there".

      Guess I just want it all ...

        Well, if you want to be sure a thread has finished, in a sense you need to know the final report has been completed -- you're just not going to read it.

        The polite thing to do is to wait for the report, collect it, but wait at least until the thread has left your office before tossing the report in the bin.

        I look at it this way: when the mother thread terminates the system could wait for all the child threads to finish before knocking the process on the head. But it cannot know that the main thread has terminated cleanly, so the children may be on its hands forever waiting for their dead mother, taking up space, demanding attention, needing to be changed, etc. So the system promptly shoot them -- it's a hard world, with no room for motherless threads.

        I suppose mother could somehow promise the system that all the children will leave soon, of their own accord. But, frankly, would you take the word of a delinquent mother ? As if !

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://723199]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-19 23:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found