public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] test-dlclose-exit-race: avoid hang on pthread_create error
@ 2021-08-04 19:33 DJ Delorie
0 siblings, 0 replies; only message in thread
From: DJ Delorie @ 2021-08-04 19:33 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=ac30324c67d94696fdb0799e9d4fc51dc70d490b
commit ac30324c67d94696fdb0799e9d4fc51dc70d490b
Author: DJ Delorie <dj@redhat.com>
Date: Tue Aug 3 16:33:29 2021 -0400
test-dlclose-exit-race: avoid hang on pthread_create error
This test depends on the "last" function being called in a
different thread than the "first" function, as "last" posts
a semaphore that "first" is waiting on. However, if pthread_create
fails - for example, if running in an older container before
the clone3()-in-container-EPERM fixes - exit() is called in the
same thread as everything else, the semaphore never gets posted,
and first hangs.
The fix is to pre-post that semaphore before a single-threaded
exit.
Reviewed-by: Arjun Shankar <arjun@redhat.com>
Diff:
---
stdlib/test-dlclose-exit-race.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/stdlib/test-dlclose-exit-race.c b/stdlib/test-dlclose-exit-race.c
index b463253281..2c44efdde6 100644
--- a/stdlib/test-dlclose-exit-race.c
+++ b/stdlib/test-dlclose-exit-race.c
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <errno.h>
#include <semaphore.h>
#include <support/check.h>
#include <support/xdlfcn.h>
@@ -64,6 +65,7 @@ last (void)
int
main (void)
{
+ int value;
void *dso;
pthread_t thread;
@@ -71,7 +73,17 @@ main (void)
dso = xdlopen ("$ORIGIN/test-dlclose-exit-race-helper.so",
RTLD_NOW|RTLD_GLOBAL);
- thread = xpthread_create (NULL, exit_thread, NULL);
+ if ((value = pthread_create (&thread, NULL, exit_thread, NULL)) != 0)
+ {
+ /* If pthread_create fails, then exit() is called in the main
+ thread instead of a second thread, so the semaphore post that
+ would have happened in 'last' gets blocked behind the call to
+ first() - which is waiting on the semaphore, and thus
+ hangs. */
+ sem_post (&order2);
+ errno = value;
+ FAIL_EXIT1 ("pthread_create: %m");
+ }
xdlclose (dso);
xpthread_join (thread);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-08-04 19:33 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-04 19:33 [glibc] test-dlclose-exit-race: avoid hang on pthread_create error DJ Delorie
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).