public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Bug #20116: Clarify barrier-like and mutex-like behaviours of PD->lock.
@ 2017-02-13 13:29 Carlos O'Donell
  2017-02-13 18:49 ` Florian Weimer
  0 siblings, 1 reply; 7+ messages in thread
From: Carlos O'Donell @ 2017-02-13 13:29 UTC (permalink / raw)
  To: GNU C Library, Florian Weimer


Florian Weimer rightly pointed out to me that we use PD->lock in two 
distinct ways, at startup in a barrier-like fashion, and later in a 
mutex-like fashion. This should be clarified in the concurrency notes
because it implies two different algorithms are at play using the same 
concurrency structure. Also note that a normal POSIX lock would not be 
valid to use in this case because it is not valid for another thread 
to unlock it (the barrier-like use-case at startup).

OK to commit?

2017-02-13  Carlos O'Donell  <carlos@redhat.com>

	[BZ #20116]
	* nptl/pthrad_create.c: Expand comments to describe barrier-like
	and mutex-like uses of PD->lock.

diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
index 2ef2bcb..b522638 100644
--- a/nptl/pthread_create.c
+++ b/nptl/pthread_create.c
@@ -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 as a POSIX
+   barrier and a POSIX mutex.  The lock is taken in the parent to force
+   the child to wait, and then the child releases the lock, in effect a
+   barrier.  However, this barrier-like effect is used only for
+   synchronizing the parent and child.  After startup the lock is used
+   like a mutex to create a critical region 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
---

-- 
Cheers,
Carlos.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-05-03 19:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-13 13:29 [PATCH] Bug #20116: Clarify barrier-like and mutex-like behaviours of PD->lock Carlos O'Donell
2017-02-13 18:49 ` Florian Weimer
2017-02-14 11:32   ` Florian Weimer
2017-03-14  1:07     ` Carlos O'Donell
2017-03-14  6:58       ` Florian Weimer
2017-03-14 12:26         ` Torvald Riegel
2017-05-03 19:25           ` Carlos O'Donell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).