[PATCH 05/14] Add lock elision to rwlocks
Dominik Vogt
vogt@linux.vnet.ibm.com
Mon Jul 1 06:15:00 GMT 2013
On Fri, Jun 28, 2013 at 03:34:17AM -0400, Carlos O'Donell wrote:
> In POSIX Issue 7:
> http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_rwlock_trywrlock.html
>
> The language for pthread_rlock_wrlock and pthread_rwlock_trywrlock says
> that it "may" deadlock, or it "may" also return EDEADLK.
>
> My reading of this is that Torvald's guideline is incorrect:
> http://sourceware.org/glibc/wiki/LockElisionGuide#Compability_with_pthreads_rwlock
>
> In that wrlock/trywrlock are not *required* to have a deadlock on relock
> semantic by the standard.
wrlock() "may fail if: [EDEADLK] A deadlock condition was detected
or the current thread already owns the read-write lock for writing
or reading." So it's apparently not required to deadlock.
trywrlock() is required to fail "if any thread currently holds
rwlock (for reading or writing)". This rules out deadlocking.
So, this statement is incorrect:
"Compability with pthreads rwlock
wrlock() / trywrlock()
No. wrlock() is required to blocking on an already locked rwlock"
> The same soft language of "may deadlock" is used for rdlock and thus the same
> flexibility is granted there.
Yes.
Ciao
Dominik ^_^ ^_^
--
Dominik Vogt
IBM Germany
More information about the Libc-alpha
mailing list