Pavel Raiskup wrote:
> POSIX says (for pthread_rwlock_wrlock()):
>
> Implementations may favor writers over readers to avoid writer starvation.
>
> But that's too far from 'shall favor' spelling.
You must be looking at an old version of POSIX [1]. POSIX:2008 specifies [2]:
[TPS] If ... the threads involved in the lock are executing with the scheduling
policies SCHED_FIFO or SCHED_RR, the calling thread shall not acquire the
lock if a writer holds the lock or if writers of higher or equal priority
are blocked on the lock; otherwise, the calling thread shall acquire the
lock.
That states pretty clearly that the goal is that if both threads have equal
priority, the "writer" thread gets the rwlock.
> It might be bug in libpthread, too, but based on the POSIX specs and manual
> pages, I am not sure whether this might be actually considered a bug.
At least a quality of implementation issue, IMO.
Bruno
[1]
http://pubs.opengroup.org/onlinepubs/007908799/xsh/pthread_rwlock_rdlock.html
[2]
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_rwlock_rdlock.html