Boost Read/Write Mutexes

This is a discussion on Boost Read/Write Mutexes within the C++ Programming forums, part of the General Programming Boards category; [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 ...

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    1

    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
    Posts
    8,892
    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!
    CornedBee

    "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, 05:11 AM
  3. Replies: 2
    Last Post: 12-12-2007, 05: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, 05:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21