diff options
author | Rich Felker <dalias@aerifal.cx> | 2013-04-26 16:05:39 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2013-04-26 16:05:39 -0400 |
commit | c3a6839ce95c0f93bd73f7fbe5fcaee4054e5b62 (patch) | |
tree | 266e3a83fb5a0ffc2ed146035c58b17f7a1f280e | |
parent | 6e531f999a82cf39a951e1e9bba3cb80a6eb1464 (diff) | |
download | musl-c3a6839ce95c0f93bd73f7fbe5fcaee4054e5b62.tar.gz musl-c3a6839ce95c0f93bd73f7fbe5fcaee4054e5b62.tar.xz musl-c3a6839ce95c0f93bd73f7fbe5fcaee4054e5b62.zip |
use atomic decrement rather than cas in pthread_exit thread count
now that blocking signals prevents any application code from running while the last thread is exiting, the cas logic is no longer needed to prevent decrementing below zero.
-rw-r--r-- | src/thread/pthread_create.c | 5 |
1 files changed, 1 insertions, 4 deletions
diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c index 6a37ee9b..0567f966 100644 --- a/src/thread/pthread_create.c +++ b/src/thread/pthread_create.c @@ -12,7 +12,6 @@ weak_alias(dummy_0, __pthread_tsd_run_dtors); _Noreturn void pthread_exit(void *result) { pthread_t self = pthread_self(); - int n; self->result = result; @@ -38,9 +37,7 @@ _Noreturn void pthread_exit(void *result) * reasons as well. */ __syscall(SYS_rt_sigprocmask, SIG_BLOCK, SIGALL_SET, 0, _NSIG/8); - do n = libc.threads_minus_1; - while (n && a_cas(&libc.threads_minus_1, n, n-1)!=n); - if (!n) exit(0); + if (a_fetch_add(&libc.threads_minus_1, -1)==0) exit(0); if (self->detached && self->map_base) { /* Detached threads must avoid the kernel clear_child_tid |