Boost logo

Boost :

Subject: Re: [boost] Performance of boost::mutex and boost::mutex::scoped_lock
From: Jonathan Franklin (franklin.jonathan_at_[hidden])
Date: 2009-06-10 12:34:44


On Wed, Jun 10, 2009 at 9:19 AM, Zachary Turner<divisortheory_at_[hidden]> wrote:
> This isn't the best multi-threaded design in the world, but
> it's basically a naive implementation of a producer consumer that uses a
> deque as the production queue, a boost::mutex as the lock, and a
> boost::condition as a signal to wake up when there's stuff in the queue
> (queue comment about boost::circular_buffer, which this code really should
> be using instead).

Are you using the "swap trick" on the queue, or synchronizing each push/pop?

I find that keeping a local queue in the thread which is processing
the shared queue, and just swapping it with the shared queue when the
local copy is empty eliminates most of the synchronization on the
queue processing side. The threads pushing work onto the shared queue
still have to synchronize, but you can't really get around that...
Even w/ shared circular buffers AFAIK.

Jon


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk