Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: How to pause multithreaded application?

by Corion (Pope)
on Sep 14, 2010 at 10:01 UTC ( #860081=note: print w/replies, xml ) Need Help??

in reply to How to pause multithreaded application?

I'm not sure what your threads are supposed to do with the currently running requests. I would let them finish their current request and have them recheck a global, shared flag whether to pause or (re)start processing. A more convoluted alternative would be to $queue->unshift dummy jobs on the threads work queue that tell each thread to pause.

If the request really is "stop whatever you're doing", have a look at the "suspend" example in threads. It seems to use signals, but as the signals are claimed to stay within the confines of Perl and seem not to be OS signals, these should be saner/safer to use with threads.

If the request only means "don't update the widget", that's easy. Have your threads send the updates to the main program through a Thread::Queue, and then either fetch or discard the log updates from that queue.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://860081]
[choroba]: But the Church Fathers say Matthew was originally in Aramaic
[Discipulus]: no erix, was ironic, I could have said Hartz4
[Discipulus]: for sure they had to be in armaic, many reverse-eng errors where spot
[Discipulus]: do you know the google like translation: a rich.. as a camel through the needle hole?

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2017-11-23 20:38 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (338 votes). Check out past polls.