Boost logo

Boost Users :

From: Delfin Rojas (drojas_at_[hidden])
Date: 2006-02-09 19:08:21


> -----Original Message-----
> From: boost-users-bounces_at_[hidden]
> [mailto:boost-users-bounces_at_[hidden]] On Behalf Of David Greene
> Sent: Thursday, February 09, 2006 1:46 PM
> To: boost-users_at_[hidden]
> Subject: [Boost-users] [thread] Mysterious deadlock
>
> I have this simple testcase (below) which runs into deadlock
<snip>

I don't understand very well why you have 2 mutexes inside Consumer. Anyway,
I left only one mutex inside Consumer which I called m_mutex and I renamed
the condition from full_condition to m_condition and changed
The Consumer::push method to this:

void push(int val) {
            LOG("push(): about to lock");
            lock_type lock(m_mutex);
            LOG("push(): locked");
            queue.push(val);
            m_condition.notify_all();
      };

And all seems to work. I ran it for a little while and producer was
generating data (ran it up to 33) and consumer was consuming data (about 17
when producer reached 33).

The boost::thread library includes several examples of this
producer/consumer pattern. Look at monitor.cpp and starvephil.cpp in
libs/thread/example

-delfin


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net