new attempt at making set*id() safe and robust
[musl] / src / thread / pthread_create.c
index d1eea0c..856015f 100644 (file)
@@ -3,8 +3,8 @@
 static void dummy_0()
 {
 }
-weak_alias(dummy_0, __rsyscall_lock);
-weak_alias(dummy_0, __rsyscall_unlock);
+weak_alias(dummy_0, __synccall_lock);
+weak_alias(dummy_0, __synccall_unlock);
 weak_alias(dummy_0, __pthread_tsd_run_dtors);
 
 #ifdef __pthread_unwind_next
@@ -22,12 +22,14 @@ void __pthread_unwind_next(struct __ptcb *cb)
                longjmp((void *)cb->__next->__jb, 1);
        }
 
-       __lock(&self->exitlock);
-
        __pthread_tsd_run_dtors();
 
+       __lock(&self->exitlock);
+
        /* Mark this thread dead before decrementing count */
+       __lock(&self->killlock);
        self->dead = 1;
+       a_store(&self->killlock, 0);
 
        do n = libc.threads_minus_1;
        while (n && a_cas(&libc.threads_minus_1, n, n-1)!=n);
@@ -97,12 +99,12 @@ int pthread_create(pthread_t *res, const pthread_attr_t *attr, void *(*entry)(vo
        new->tlsdesc[1] = (uintptr_t)new;
        stack = (void *)((uintptr_t)new-1 & ~(uintptr_t)15);
 
-       __rsyscall_lock();
+       __synccall_lock();
 
        a_inc(&libc.threads_minus_1);
        ret = __uniclone(stack, start, new);
 
-       __rsyscall_unlock();
+       __synccall_unlock();
 
        if (ret < 0) {
                a_dec(&libc.threads_minus_1);