Bug #20116: Clarify barrier-like and mutex-like behaviours of PD->lock.
Commit Message
On 03/14/2017 08:26 AM, Torvald Riegel wrote:
> It's not a barrier actually, but closer to a semaphore (the parent does
> not wait for the child to arrive, but continues immediately after
> posting...).
I integrated Torvald's comments and this is what I checked in.
I believe this suffices to clarify the concurrency notes for the
case Florian wanted clarified.
2017-05-03 Carlos O'Donell <carlos@redhat.com>
[BZ #20116]
* nptl/pthrad_create.c: Expand comments to describe
semaphore-like and mutex-like uses of PD->lock.
@@ -94,8 +94,17 @@ unsigned int __nptl_nthreads = 1;
exactly which of the four ownership states we are in and therefore
what actions can be taken. For example after (2) we cannot read or
write from PD anymore since the thread may no longer exist and the
- memory may be unmapped. The most complicated cases happen during
- thread startup:
+ memory may be unmapped.
+
+ It is important to point out that PD->lock is being used both
+ similar to a one-shot semaphore and subsequently as a mutex. The
+ lock is taken in the parent to force the child to wait, and then the
+ child releases the lock. However, this semaphore-like effect is used
+ only for synchronizing the parent and child. After startup the lock
+ is used like a mutex to create a critical section during which a
+ single owner modifies the thread parameters.
+
+ The most complicated cases happen during thread startup:
(a) If the created thread is in a detached (PTHREAD_CREATE_DETACHED),
or joinable (default PTHREAD_CREATE_JOINABLE) state and