read / write locks and deadlock detection

Discussion in 'C++' started by Jürgen Devlieghere, Nov 29, 2005.

  1. Hi,

    We are creating event-driven multi-threaded applications on a daily basis.
    To help us solving deadlocks, we implemented a CriticalSection class that
    does dead-lock detection: an attempt to Enter() the critical section that
    would cause a deadlock logs the complete deadlock loop (thread / Critical
    section) and raises an exception. It has helped us a lot in the past.

    However, to prevent further deadlocks, and to get a higher performance, we
    want to implement read / write locks.

    So, we need:
    - read / write locks
    - with deadlock detection
    - the locks should be re-entrant (like a mutex: a thread can ask again for
    the lock and gets it immediately. There is a counter inside that ensures
    that the lock is only released after an equal number of calls of Leave() as
    there were of Enter().

    I found a good article about how to implement a read/write lock on MSDN
    written by Ruediger R. Asche, but that code doesn't support re-entrance by
    the same thread.

    Any of you has a reference to a good article / source code / library?

    I realize there are ways to avoid dead-locks:
    - work with 1 worker thread (bad performance on multi-processor)
    - collect data on the higher level and pass that along. That we did for as
    long as the data still was contained where it belonged.

    Jürgen
    Jürgen Devlieghere, Nov 29, 2005
    #1
    1. Advertising

  2. "Jürgen Devlieghere" <> writes:

    > Hi,
    >
    > We are creating event-driven multi-threaded applications on a daily basis.


    [snip]

    Try comp.programming.threads.

    /Niklas Norrthon
    Niklas Norrthon, Nov 29, 2005
    #2
    1. Advertising

  3. Jürgen Devlieghere

    peter koch Guest

    Jürgen Devlieghere skrev:

    > Hi,
    >
    > We are creating event-driven multi-threaded applications on a daily basis.
    > To help us solving deadlocks, we implemented a CriticalSection class that
    > does dead-lock detection: an attempt to Enter() the critical section that
    > would cause a deadlock logs the complete deadlock loop (thread / Critical
    > section) and raises an exception. It has helped us a lot in the past.
    >
    > However, to prevent further deadlocks, and to get a higher performance, we
    > want to implement read / write locks.
    >
    > So, we need:
    > - read / write locks
    > - with deadlock detection
    > - the locks should be re-entrant (like a mutex: a thread can ask again for
    > the lock and gets it immediately. There is a counter inside that ensures
    > that the lock is only released after an equal number of calls of Leave() as
    > there were of Enter().
    >
    > I found a good article about how to implement a read/write lock on MSDN
    > written by Ruediger R. Asche, but that code doesn't support re-entrance by
    > the same thread.


    Reentrancy is not something you should strive for unless it is
    absolutely necessary. In my code I do checks when using reentrant
    mutexes (or critical section or whatever you call the beast) that the
    mutex is not locked twice by the same thread. The reason is (put
    briefly) that you better know what your code is up to.
    But this is all for comp.programming.threads where you should direct
    your questions.

    /Peter
    [snip]
    > Jürgen
    peter koch, Nov 29, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    343
  2. Replies:
    1
    Views:
    330
    Robert Klemme
    Jun 1, 2004
  3. Matt
    Replies:
    2
    Views:
    851
    Kristo
    Apr 22, 2005
  4. Duncan Grisby

    Deadlock detection

    Duncan Grisby, Dec 6, 2004, in forum: Python
    Replies:
    7
    Views:
    577
    Mike Meyer
    Dec 11, 2004
  5. Jaydeep Chovatia

    pthread rwlock deadlock detection

    Jaydeep Chovatia, Oct 5, 2011, in forum: C++
    Replies:
    2
    Views:
    971
    Ian Collins
    Oct 6, 2011
Loading...

Share This Page