Concurrency issues in reader-writer problem

Discussion in 'C++' started by Hunk, Feb 21, 2007.

  1. Hunk

    Hunk Guest


    I would like some ideas on way to solve the concurrency issue. The
    problem is , I have an object say X which multiple readers need to
    access and also to update. They do so by say two functions :
    // simplistic view of the problem
    return X;

    X= Y;

    Now I would like to block any reader while calling update. With the
    general solutions provided of having say a mutex and using it in Read
    and Update would solve the problem. But then this would block multiple
    readers also which is not desired. i.e a block on read should be
    allowed only when update is called. Having a boolean and checkin is
    not ideal as the atomicity of the operation is not guaranteed. Any
    ideas on this?
    Hunk, Feb 21, 2007
    1. Advertisements

  2. Hunk

    dasjotre Guest

    you nead reader-writer lock. the best implementation I've
    seen is Valery Pryamikov's mrsw_guard
    dasjotre, Feb 21, 2007
    1. Advertisements

  3. Hunk

    Bharath Guest

    Is this a multi-threaded program? If it is, the best solution is to
    use read-write locks in pthread library. See the manpage of
    pthread_rwlock_wrlock and pthread_rwlock_rdlock. Note that you need to
    have -DUSE_UNIX98 in your compiler flags.
    Bharath, Feb 21, 2007
  4. Hunk

    Hunk Guest

    Thanks... yes it is a multithreaded program. i'll take a look at the
    reader writer locks mentioned. Any idea on how this is implemented in
    Hunk, Feb 22, 2007
  5. Hunk

    Bharath Guest

    Bharath, Feb 22, 2007
  6. how does it compare to the following algorithm:
    Chris Thomasson, Feb 23, 2007
  7. Chris Thomasson, Feb 23, 2007
  8. Chris Thomasson, Feb 23, 2007
  9. Chris Thomasson, Feb 23, 2007
  10. Chris Thomasson, Feb 23, 2007
  11. Hunk

    Hunk Guest

    Hey chris , thanks a lot for the ton of information given. I'm just
    browsing through it.. appears to be good. i'll just see if there's a
    way to choose between the implementations.
    Hunk, Feb 23, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.