|
Boost Users : |
Subject: Re: [Boost-users] Boost Threading Multiple Reader / Single Writer Usage Questions
From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2010-02-19 05:16:49
Brian Nantz <brian_at_[hidden]> writes:
> 1.       There could be nested locks and the RWL should handle unwinding them
> correctly. I see that recursive_mutex seems to handle that. Does shared_mutex
> handle that as well?
shared_mutex does not support nested locks by the same thread.
> 2.       Is there a way to give a higher priority to writes? I am worried
> about the readers starving the writers, so I would like any pending writers to
> be given preference over pending readers.
If there are pending writers then new readers are queued. When the
current lock is released (whether reader or writer) then writers +
readers compete for the lock.
> How can I get this functionality from the Boost thread library? If I need to
> build my own, what class do you recommend using as a base to build from?
You may actually better NOT using a read/write lock. The lock itself is
a point of contention, and for many short-lived readers (the natural use
of a read/write lock) the time locking/unlocking may be a significant
portion of the overall execution time, especially on multi-core and
multi-processor systems. Joe Duffy posted some timings on his blog:
Anthony
-- Author of C++ Concurrency in Action http://www.stdthread.co.uk/book/ just::thread C++0x thread library http://www.stdthread.co.uk Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976
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