|
Boost : |
From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2001-08-13 13:38:42
> synchronized_queue<int> q;
> event e;
^^^^^^^
auto-reset event, i guess..
>
> void threadfunc()
> {
> for(;;)
> {
> waitFor(e);
>
> while(!q.empty())
> {
> int m = q.pop();
> if(m & 1) do_something_a();
> if(m & 2) do_something_b();
> if(m & 4) do_something_c();
> }
> }
> }
>
> void notifyThread(bool a, bool b, bool c)
> {
> q.push(a + 2 * b + 4 * c);
> e.raise();
> }
>
> Did I utterly miss the point? :-)
probably. you have introduced a race
condition which could result in q.pop()
throwing "queue empty" exception; unless
you have only one worker thread.
regards,
alexander.
ps.
>> mutex m;
>> condition cv;
>> volatile bool a = false, b = false, c = false;
^^^^^^^^
you do not need volatiles here.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk