diff options
author | Florian Weimer <fweimer@redhat.com> | 2020-05-20 15:40:35 +0200 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2020-07-06 11:15:58 +0200 |
commit | 706ad1e7af37be1d25fc2359bda006d31fe0d11b (patch) | |
tree | d06e6a96c1d319a1d27fa6b6e87cfadf8bd6ef08 /htl | |
parent | 8f4632deb3545b2949cec5454afc3cb21a0024ea (diff) | |
download | glibc-706ad1e7af37be1d25fc2359bda006d31fe0d11b.tar.gz glibc-706ad1e7af37be1d25fc2359bda006d31fe0d11b.tar.xz glibc-706ad1e7af37be1d25fc2359bda006d31fe0d11b.zip |
Add the __libc_single_threaded variable
The variable is placed in libc.so, and it can be true only in an outer libc, not libcs loaded via dlmopen or static dlopen. Since thread creation from inner namespaces does not work, pthread_create can update __libc_single_threaded directly. Using __libc_early_init and its initial flag, implementation of this variable is very straightforward. A future version may reset the flag during fork (but not in an inner namespace), or after joining all threads except one. Reviewed-by: DJ Delorie <dj@redhat.com>
Diffstat (limited to 'htl')
-rw-r--r-- | htl/pt-create.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/htl/pt-create.c b/htl/pt-create.c index f501a12017..7ac875cbf7 100644 --- a/htl/pt-create.c +++ b/htl/pt-create.c @@ -24,6 +24,7 @@ #include <atomic.h> #include <hurd/resource.h> +#include <sys/single_threaded.h> #include <pt-internal.h> #include <pthreadP.h> @@ -104,6 +105,10 @@ __pthread_create_internal (struct __pthread **thread, sigset_t sigset; size_t stacksize; + /* Avoid a data race in the multi-threaded case. */ + if (__libc_single_threaded) + __libc_single_threaded = 0; + /* Allocate a new thread structure. */ err = __pthread_alloc (&pthread); if (err) |