aboutsummaryrefslogtreecommitdiffstats
path: root/libc/bionic/pthread_create.cpp
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2015-03-17 18:12:58 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-03-17 18:12:59 +0000
commit94babaee1b6598b15bd807461055d4dcaaa52f10 (patch)
tree0efa7df548f74df352be643bc640202606ce0347 /libc/bionic/pthread_create.cpp
parent5490bebd7cdd4406780358f590391b75ab8a7d84 (diff)
parent58cf31b50699ed9f523de38c8e943f3bbd1ced9e (diff)
downloadandroid_bionic-94babaee1b6598b15bd807461055d4dcaaa52f10.tar.gz
android_bionic-94babaee1b6598b15bd807461055d4dcaaa52f10.tar.bz2
android_bionic-94babaee1b6598b15bd807461055d4dcaaa52f10.zip
Merge "Make pthread join_state not protected by g_thread_list_lock."
Diffstat (limited to 'libc/bionic/pthread_create.cpp')
-rw-r--r--libc/bionic/pthread_create.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/libc/bionic/pthread_create.cpp b/libc/bionic/pthread_create.cpp
index 2bca43f83..a4bd054c7 100644
--- a/libc/bionic/pthread_create.cpp
+++ b/libc/bionic/pthread_create.cpp
@@ -86,6 +86,12 @@ void __init_alternate_signal_stack(pthread_internal_t* thread) {
int __init_thread(pthread_internal_t* thread, bool add_to_thread_list) {
int error = 0;
+ if (__predict_true((thread->attr.flags & PTHREAD_ATTR_FLAG_DETACHED) == 0)) {
+ atomic_init(&thread->join_state, THREAD_NOT_JOINED);
+ } else {
+ atomic_init(&thread->join_state, THREAD_DETACHED);
+ }
+
// Set the scheduling policy/priority of the thread.
if (thread->attr.sched_policy != SCHED_NORMAL) {
sched_param param;
@@ -263,7 +269,7 @@ int pthread_create(pthread_t* thread_out, pthread_attr_t const* attr,
if (init_errno != 0) {
// Mark the thread detached and replace its start_routine with a no-op.
// Letting the thread run is the easiest way to clean up its resources.
- thread->attr.flags |= PTHREAD_ATTR_FLAG_DETACHED;
+ atomic_store(&thread->join_state, THREAD_DETACHED);
thread->start_routine = __do_nothing;
pthread_mutex_unlock(&thread->startup_handshake_mutex);
return init_errno;