apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Orton <jor...@redhat.com>
Subject Re: Can a thread write-lock a rwlock that it already has read-locked?
Date Fri, 15 Oct 2004 07:27:00 GMT
On Thu, Oct 14, 2004 at 06:17:39PM -0600, David Barrett wrote:
> I'm experimenting with the reader/writer locks and have a question:
> 
> 	Can a thread write-lock a thread on which it already holds the read
> lock?

Hey, I answered that one already :) apr_thread_rwlock.h in 1.0 says:

 * Note: The following operations have undefined results: unlocking a
 * read-write lock which is not locked in the calling thread; write
 * locking a read-write lock which is already locked by the calling
 * thread; ...

> My followup question is, is there any way to override this behavior?  It
> would seem to me that a thread could safely hold both a read and write lock,
> so long as no other thread held either.  Furthermore, it'd be nice to give
> up the write lock without giving up the read lock.  The pattern I'd like to
> use is something like:

No, there's no way round it, APR just matches what the underlying rwlock
semantics are.  It's just the case that you have to take the write lock
up front if you're going to be making changes, I suppose.

joe

Mime
View raw message