Sign in to follow this  

POSIX and Win32 waiting for multiple conditiions simultaneously

Recommended Posts

In Win32, one can easily wait for all sync objects of some set to be set before continuing using the WaitForMultipleObjects API call. However, with POSIX pthreads, the functionality doesnt exist. I have only found one paper that attempts to explain how to simulate such functionality, but it is written horibly. (At least i can get the author's incoherent psuedo-crap) ( I am implementing a read write lock based on this article. In its source code for its RWLockEx, it waits simultaneously for a mutex that syncs general access to the lock (to maintain lock consistancy) and an another mutex used for writer exclusion. Attempting to lock these items independantly one after the (even with a loop to check on lock-state consistancy) results in deadlock. Two threads will compete for a lock, both locking first the access lock and then the write mutex. the second waits on the write mutex, which prevents it from ever freeing its access mutex. in order for the 1st thread to release its write lock, it needs to lock the access mutex which is held in limbo by thread 2 waiting on thread 1. Thread 1 now waits and results in DEADLOCK. By simply waiting for both the mutexes at the same time, thread 2 would be completely blocked from ever getting far enough to deadlock with thread 1. Any susggestions on how to solve this issue would be awsome! Thanks....

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this