Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Kill and free the memory Never ending threads from main

by sundialsvc4 (Abbot)
on Aug 25, 2013 at 14:51 UTC ( #1050861=note: print w/ replies, xml ) Need Help??


in reply to Kill and free the memory Never ending threads from main

Approach the problem this way:   the event just means, “you should not be asleep right now.”   (Not “please wake up.”)   The main-loop of the thread is driven by a set of shared flags which tell it what it should do next, one of the choices being “die now.”

while (1) { if (shared.die) { exit; } elsif (shared.do_this) { do_this; } elsif (shared.do_that) { do_that; } ... else { wait_for_event(); } }

The parent thread first sets one of the flags, then strobes the event to be sure that the child is not-asleep to respond to it.

You don’t need to invent these things from scratch.   Look at existing workhorses such as POE.


Comment on Re: Kill and free the memory Never ending threads from main
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (11)
As of 2015-07-06 21:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (83 votes), past polls