From 8584beae8e0f4ac4a5c128d35da43241761501db Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 18 Jun 2018 18:16:34 +0200 Subject: [PATCH] pthread_rwlock_rdlock: Add comments regarding glibc behaviour. * m4/pthread_rwlock_rdlock.m4: Add comment. * doc/posix-functions/pthread_rwlock_rdlock.texi: Mention that rwlocks are reader-preferring in glibc. * doc/posix-functions/pthread_rwlock_tryrdlock.texi: Likwise. * doc/posix-functions/pthread_rwlock_timedrdlock.texi: Likewise. --- ChangeLog | 9 +++++++++ doc/posix-functions/pthread_rwlock_rdlock.texi | 9 +++++++++ doc/posix-functions/pthread_rwlock_timedrdlock.texi | 7 +++++++ doc/posix-functions/pthread_rwlock_tryrdlock.texi | 7 +++++++ m4/pthread_rwlock_rdlock.m4 | 8 +++++--- 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1bda21b275..beaaf26a58 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2018-06-18 Bruno Haible + + pthread_rwlock_rdlock: Add comments regarding glibc behaviour. + * m4/pthread_rwlock_rdlock.m4: Add comment. + * doc/posix-functions/pthread_rwlock_rdlock.texi: Mention that rwlocks + are reader-preferring in glibc. + * doc/posix-functions/pthread_rwlock_tryrdlock.texi: Likwise. + * doc/posix-functions/pthread_rwlock_timedrdlock.texi: Likewise. + 2018-06-17 Paul Eggert crypto: use byteswap diff --git a/doc/posix-functions/pthread_rwlock_rdlock.texi b/doc/posix-functions/pthread_rwlock_rdlock.texi index 3759f782e1..387dabed77 100644 --- a/doc/posix-functions/pthread_rwlock_rdlock.texi +++ b/doc/posix-functions/pthread_rwlock_rdlock.texi @@ -15,4 +15,13 @@ Portability problems not fixed by Gnulib: @item This function is missing on some platforms: Minix 3.1.8, HP-UX 11, OSF/1 4.0, Solaris 2.6, mingw, MSVC 14, BeOS. +@item +This function prefers readers to writers (meaning, when this function is +called on an rwlock that is already taken by one or more readers, and +another writer is already waiting to take it, this function may return +successfully immediately) -- a behaviour that may lead to writer starvation -- +on some platforms: +glibc 2.28. +As a workaround, you can use the @code(gl_rwlock_t} type from the Gnulib +module @samp{lock}. @end itemize diff --git a/doc/posix-functions/pthread_rwlock_timedrdlock.texi b/doc/posix-functions/pthread_rwlock_timedrdlock.texi index 07194c1387..52cc74a789 100644 --- a/doc/posix-functions/pthread_rwlock_timedrdlock.texi +++ b/doc/posix-functions/pthread_rwlock_timedrdlock.texi @@ -15,4 +15,11 @@ Portability problems not fixed by Gnulib: @item This function is missing on some platforms: Mac OS X 10.5, FreeBSD 5.2.1, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 9, Cygwin, mingw, MSVC 14, BeOS. +@item +This function prefers readers to writers (meaning, when this function is +called on an rwlock that is already taken by one or more readers, and +another writer is already waiting to take it, this function may return +successfully immediately) -- a behaviour that may lead to writer starvation -- +on some platforms: +glibc 2.28. @end itemize diff --git a/doc/posix-functions/pthread_rwlock_tryrdlock.texi b/doc/posix-functions/pthread_rwlock_tryrdlock.texi index 370a899aae..b817212e97 100644 --- a/doc/posix-functions/pthread_rwlock_tryrdlock.texi +++ b/doc/posix-functions/pthread_rwlock_tryrdlock.texi @@ -15,4 +15,11 @@ Portability problems not fixed by Gnulib: @item This function is missing on some platforms: Minix 3.1.8, HP-UX 11, OSF/1 4.0, Solaris 2.6, mingw, MSVC 14, BeOS. +@item +This function prefers readers to writers (meaning, when this function is +called on an rwlock that is already taken by one or more readers, and +another writer is already waiting to take it, this function may return +successfully immediately) -- a behaviour that may lead to writer starvation -- +on some platforms: +glibc 2.28. @end itemize diff --git a/m4/pthread_rwlock_rdlock.m4 b/m4/pthread_rwlock_rdlock.m4 index 9c1d5d0193..6812b4f4e2 100644 --- a/m4/pthread_rwlock_rdlock.m4 +++ b/m4/pthread_rwlock_rdlock.m4 @@ -1,4 +1,4 @@ -# pthread_rwlock_rdlock.m4 serial 1 +# pthread_rwlock_rdlock.m4 serial 2 dnl Copyright (C) 2017-2018 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -23,12 +23,14 @@ dnl time, a phenomenon called "writer starvation". dnl Without such a guarantee, applications have a hard time avoiding writer dnl starvation. dnl -dnl POSIX:2008 makes this requirement only for implementations that support TPS +dnl POSIX:2017 makes this requirement only for implementations that support TPS dnl (Thread Priority Scheduling) and only for the scheduling policies SCHED_FIFO dnl and SCHED_RR, see dnl http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_rwlock_rdlock.html -dnl but test verifies the guarantee regardless of TPS and regardless of +dnl but this test verifies the guarantee regardless of TPS and regardless of dnl scheduling policy. +dnl Glibc currently does not provide this guarantee, see +dnl https://sourceware.org/bugzilla/show_bug.cgi?id=13701 AC_DEFUN([gl_PTHREAD_RWLOCK_RDLOCK_PREFER_WRITER], [ AC_REQUIRE([gl_THREADLIB_EARLY]) -- 2.39.5