I'm using read/write locks on Linux and I've found that trying to upgrade a read locked object to a write lock deadlocks.
// acquire the read lock in thread 1.
pthread_rwlock_rdlock( &lock );
// make a decision to upgrade the lock in threads 1.
pthread_rwlock_wrlock( &lock ); // this deadlocks as already hold read lock.
The calling thread may deadlock if at
the time the call is made it holds the
read-write lock (whether a read or
What else than a dead lock do you want in the following scenario?
So I'd just release the read lock, acquire the write lock and check again if I've to make the update or not.