
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of David Greene Sent: Thursday, February 09, 2006 1:46 PM To: boost-users@lists.boost.org 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