in reply to Re^2: failing with Thread::Queue
in thread failing with Thread::Queue
Re-reading your post, I should also comment on:
I had tried using a simple shared scalar before, but I thought I had to use cond_wait() and locking and friends
Technically, you should use locking on shared vars.
You will rarely, if ever, need to use cond_*(), and I would suggest you pretend they don't exist until you encounter the situation that you cannot deal with without them.
I write a lot of threaded code, and I've only had to use them about 3 or 4 time in total over the past 8 or 9 years.
For this specific case, even the need for lock is moot. The shared var is either true or false. When the value is about to change, readers will either see it just before it changes and loop once more, or they will see it just after it changed and terminate.
Locking it before changing it; or before reading it; will make no quantifiable difference to the order in which things happen; it is therefore redundant -- in this case!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: failing with Thread::Queue
by rastoboy (Monk) on Mar 22, 2012 at 22:10 UTC |