Rich Felker wrote:
> It's using the raw pthread lock and it's completely expected that it
> fails with >10 cores since there will always be multiple readers
> scheduled and no chance for a writer to run.
Yes, that's the phenomenon known as "writer starvation".
> This is necessitated by
> POSIX rwlocks being required to be recursive and the impossibility of
> making recursive locking only possible for threads which already hold
> a read lock (due to impossibility to track that in O(1) storage).
I did a survey of the various behaviours of rwlock implementations [1].
Find the results there [2]. In particular:
Solaris 11
When releasing the last reader lock:
If at least one of the enqueued lock attempts is for writing, one
of them is granted.
When releasing a writer lock:
If at least one of the enqueued lock attempts is for writing, one of
the waiting write attempts is granted (not necessarily the first one).
Otherwise, one of the waiting read attempts is granted.
This implementation does not prefer readers.
This implementation always prefers writers.
gnulib on native Windows
When releasing the last reader lock:
The first of the enqueued lock attempts is granted.
When releasing a writer lock:
If at least one of the enqueued lock attempts is for writing, the
first one of them is granted.
Otherwise, the first of the waiting read attempts is granted.
This implementation does not prefer readers.
This implementation does not globally prefer writers, only when releasing
a writer lock.
This implementation is deterministic.
Are you saying that the Solaris 11 and gnulib behaviours are not POSIX
compliant? If so, please can you highlight precisely which sentence in
POSIX [3][4] they are violating? (I don't see the word "recursive" there.)
Bruno
[1]
https://gitweb.git.savannah.gnu.org/gitweb/?p=gnulib/maint-tools.git;a=tree;f=test-programs/pthread-rwlock;h=bc63cb8ee32bf508f0b7daab6f367fd507786a2b;hb=HEAD
[2]
https://gitweb.git.savannah.gnu.org/gitweb/?p=gnulib/maint-tools.git;a=blob_plain;f=test-programs/pthread-rwlock/results.txt;hb=HEAD
[3]
https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/functions/pthread_rwlock_rdlock.html
[4]
https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/functions/pthread_rwlock_trywrlock.html