Thread: Boost Read/Write Mutexes

  1. #1
    Registered User
    Join Date
    Jun 2009

    Boost Read/Write Mutexes

    [Mod note: Split from here]

    I have worked with boost::shared_mutex and boost::shared_lock, boost::unique_lock as specified to acieve multiple readers single writer.

    Unfortunately I found out that when writer is working Boost does not allow reader access EVEN the reader is from the SAME thread!

    And vice versa, When reader is working, Boost does not allow writer access EVEN the writer is from the SAME thread!

    I just want to mention that this scenario is of course possible.
    For instance, if there is a big block of code - read protected. Inside this block there is a small general routine that need a write access.

    I don't want to change the whole code block to write access since it unnecessarily prevents other readers to run when it it possible to do so.

    Closing the reader before writer starts and reopening it after the writer finish cause too much overhead.

    Is there any answer within boost framework to this scenario?

    Zafrir Patt 11/6/09
    Last edited by CornedBee; 06-11-2009 at 09:36 AM.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    That's what upgradeable locks are for. However, notice that only one upgradeable reader is possible at any one time (shared with any number of pure readers).

    I've split this into a new thread. Please start new threads for new questions.
    Last edited by CornedBee; 06-11-2009 at 09:34 AM.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. condition variable on read/write locks
    By ShwangShwing in forum C Programming
    Replies: 3
    Last Post: 04-29-2009, 09:32 AM
  2. Boost Auto-Linking
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 12-30-2007, 06:11 AM
  3. Replies: 2
    Last Post: 12-12-2007, 06:45 AM
  4. building boost iostreams
    By l2u in forum C++ Programming
    Replies: 3
    Last Post: 04-14-2007, 02:29 PM
  5. Integrating Boost with STLPort
    By Mario F. in forum Tech Board
    Replies: 1
    Last Post: 11-11-2006, 06:49 AM