public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Florian Weimer <fw@sourceware.org>
To: glibc-cvs@sourceware.org
Subject: [glibc/release/2.34/master] nptl: Add one more barrier to nptl/tst-create1
Date: Fri, 10 Dec 2021 10:56:39 +0000 (GMT)	[thread overview]
Message-ID: <20211210105639.5DEC63858D35@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=e9f81c261a2ca74d31d07ff9c8e780ac8a25993c

commit e9f81c261a2ca74d31d07ff9c8e780ac8a25993c
Author: Florian Weimer <fweimer@redhat.com>
Date:   Fri Dec 10 05:14:24 2021 +0100

    nptl: Add one more barrier to nptl/tst-create1
    
    Without the bar_ctor_finish barrier, it was possible that thread2
    re-locked user_lock before ctor had a chance to lock it.  ctor then
    blocked in its locking operation, xdlopen from the main thread
    did not return, and thread2 was stuck waiting in bar_dtor:
    
    thread 1: started.
    thread 2: started.
    thread 2: locked user_lock.
    constructor started: 0.
    thread 1: in ctor: started.
    thread 3: started.
    thread 3: done.
    thread 2: unlocked user_lock.
    thread 2: locked user_lock.
    
    Fixes the test in commit 83b5323261bb72313bffcf37476c1b8f0847c736
    ("elf: Avoid deadlock between pthread_create and ctors [BZ #28357]").
    
    Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
    (cherry picked from commit 5cc338565479a620244c2f8ff35956629c4dbf81)

Diff:
---
 NEWS                          | 1 +
 sysdeps/pthread/tst-create1.c | 4 ++++
 2 files changed, 5 insertions(+)

diff --git a/NEWS b/NEWS
index 8c68273929..698964bb9e 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,7 @@ The following bugs are resolved with this release:
   [28524] Conversion from ISO-2022-JP-3 with iconv may emit spurious NULs
   [28607] Masked signals are delivered on thread exit
   [28532] powerpc64[le]: CFI for assembly templated syscalls is incorrect
+  [28678] nptl/tst-create1 hangs sporadically
 
 \f
 Version 2.34
diff --git a/sysdeps/pthread/tst-create1.c b/sysdeps/pthread/tst-create1.c
index 932586c309..763ded8d79 100644
--- a/sysdeps/pthread/tst-create1.c
+++ b/sysdeps/pthread/tst-create1.c
@@ -33,6 +33,7 @@ thread 2: lock(user_lock) -> pthread_create
 */
 
 static pthread_barrier_t bar_ctor;
+static pthread_barrier_t bar_ctor_finish;
 static pthread_barrier_t bar_dtor;
 static pthread_mutex_t user_lock = PTHREAD_MUTEX_INITIALIZER;
 
@@ -46,6 +47,7 @@ ctor (void)
   xpthread_mutex_unlock (&user_lock);
   dprintf (1, "thread 1: in ctor: unlocked user_lock.\n");
   dprintf (1, "thread 1: in ctor: done.\n");
+  xpthread_barrier_wait (&bar_ctor_finish);
 }
 
 void
@@ -81,6 +83,7 @@ thread2 (void *a)
   xpthread_mutex_unlock (&user_lock);
   dprintf (1, "thread 2: unlocked user_lock.\n");
   xpthread_join (t3);
+  xpthread_barrier_wait (&bar_ctor_finish);
 
   xpthread_mutex_lock (&user_lock);
   dprintf (1, "thread 2: locked user_lock.\n");
@@ -99,6 +102,7 @@ thread1 (void)
 {
   dprintf (1, "thread 1: started.\n");
   xpthread_barrier_init (&bar_ctor, NULL, 2);
+  xpthread_barrier_init (&bar_ctor_finish, NULL, 2);
   xpthread_barrier_init (&bar_dtor, NULL, 2);
   pthread_t t2 = xpthread_create (0, thread2, 0);
   void *p = xdlopen ("tst-create1mod.so", RTLD_NOW | RTLD_GLOBAL);


                 reply	other threads:[~2021-12-10 10:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211210105639.5DEC63858D35@sourceware.org \
    --to=fw@sourceware.org \
    --cc=glibc-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).