From patchwork Thu Nov 15 15:03:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos O'Donell X-Patchwork-Id: 30149 Received: (qmail 9572 invoked by alias); 15 Nov 2018 15:03:52 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 9558 invoked by uid 89); 15 Nov 2018 15:03:52 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=earned, retirement, analog, 11517 X-HELO: mail-qk1-f170.google.com Return-Path: To: "linux-man@vger.kernel.org" , Michael Kerrisk From: Carlos O'Donell Subject: [patch] pthread_rwlockattr_setkind_np.3: Remove bug notes. Openpgp: preference=signencrypt Cc: GNU C Library Message-ID: Date: Thu, 15 Nov 2018 10:03:41 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 The notes in pthread_rwlockattr_setkind_np.3 imply there is a bug in glibc's implementation of PTHREAD_RWLOCK_PREFER_WRITER_NP (a non-portable constant anyway), but this is not true. The implementation of PTHREAD_RWLOCK_PREFER_WRITER_NP is made almost impossible by the POSIX standard requirement that reader locks be allowed to be recursive, and that requirement makes writer preference deadlock without an impossibly complex requirement that we track all reader locks. Therefore the only sensible solution was to add PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP and disallow recursive reader locks if you want writer preference. This patch removes the bug description and documents the current state and recommendations for glibc. I have also updated bug 7057 with this information, answering Steven Munroe's almost 10 year old question :-) I hope Steven is enjoying his much earned retirement. Tested on master. Please apply to master. Should we move the glibc discussion to some footnote? Some libc may be able to implement the requirement to avoid deadlocks in the future, but I doubt it (fundamental CS stuff). --- Cheers, Carlos. diff --git a/man3/pthread_rwlockattr_setkind_np.3 b/man3/pthread_rwlockattr_setkind_np.3 index 3cca7d864..6b2b8db39 100644 --- a/man3/pthread_rwlockattr_setkind_np.3 +++ b/man3/pthread_rwlockattr_setkind_np.3 @@ -79,7 +79,31 @@ starved. .B PTHREAD_RWLOCK_PREFER_WRITER_NP This is intended as the write lock analog of .BR PTHREAD_RWLOCK_PREFER_READER_NP . -But see BUGS. +This is ignored by glibc because the POSIX requirement to support +recursive writer locks would cause this option to create trivial +deadlocks; instead use +.B PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP +which ensures the application developer will not take recursive +read locks thus avoiding deadlocks. +.\" --- +.\" Here is the relevant wording: +.\" +.\" A thread may hold multiple concurrent read locks on rwlock (that is, +.\" successfully call the pthread_rwlock_rdlock() function n times). If +.\" so, the thread must perform matching unlocks (that is, it must call +.\" the pthread_rwlock_unlock() function n times). +.\" +.\" By making write-priority work correctly, I broke the above requirement, +.\" because. I had no clue that recursive read locks are permissible. +.\" +.\" If a thread which holds a read lock tries to acquire another read lock, +.\" and now one or more writers is waiting for a write lock, then the algorithm +.\" will lead to an obvious deadlock. The reader will be suspended, waiting for +.\" the writers to acquire and release the lock, and the writers will be +.\" suspended waiting for every existing read lock to be released. +.\" --- +.\" http://sources.redhat.com/ml/libc-alpha/2000-01/msg00055.html +.\" https://sourceware.org/bugzilla/show_bug.cgi?id=7057 .TP .B PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP Setting the lock kind to this @@ -115,17 +139,5 @@ functions first appeared in glibc 2.1. .SH CONFORMING TO These functions are non-standard GNU extensions; hence the suffix "_np" (nonportable) in the names. -.SH BUGS -Setting the value read-write lock kind to -.BR PTHREAD_RWLOCK_PREFER_WRITER_NP -results in the same behavior as setting the value to -.BR PTHREAD_RWLOCK_PREFER_READER_NP . -As long as a reader thread holds the lock, the thread holding a -write lock will be starved. -Setting the lock kind to -.BR PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP -allows writers to run, but, as the name implies a writer -may not lock recursively. -.\" http://sourceware.org/bugzilla/show_bug.cgi?id=7057 .SH SEE ALSO .BR pthreads (7)