summaryrefslogtreecommitdiffstats
path: root/lib/libkse/thread/thr_join.c
diff options
context:
space:
mode:
authordeischen <deischen@FreeBSD.org>2003-05-24 02:29:25 +0000
committerdeischen <deischen@FreeBSD.org>2003-05-24 02:29:25 +0000
commitdc5114efb5a7accba1140bb50db1def228a37531 (patch)
treee99d3167d044ff37cf6b26fa4f4fe83140c8af79 /lib/libkse/thread/thr_join.c
parentd8dec9f72fc70ddb0f6dc6547bc8207a1061187d (diff)
downloadFreeBSD-src-dc5114efb5a7accba1140bb50db1def228a37531.zip
FreeBSD-src-dc5114efb5a7accba1140bb50db1def228a37531.tar.gz
Change low-level locking a bit so that we can tell if
a lock is being waitied on. Fix a races in join and cancellation. When trying to wait on a CV and the library is not yet threaded, make it threaded so that waiting actually works. When trying to nanosleep() and we're not threaded, just call the system call nanosleep instead of adding the thread to the wait queue. Clean up adding/removing new threads to the "all threads queue", assigning them unique ids, and tracking how many active threads there are. Do it all when the thread is added to the scheduling queue instead of making pthread_create() know how to do it. Fix a race where a thread could be marked for signal delivery but it could be exited before we actually add the signal to it. Other minor cleanups and bug fixes. Submitted by: davidxu Approved by: re@ (blanket for libpthread)
Diffstat (limited to 'lib/libkse/thread/thr_join.c')
-rw-r--r--lib/libkse/thread/thr_join.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/libkse/thread/thr_join.c b/lib/libkse/thread/thr_join.c
index dd69bbb..d6add88 100644
--- a/lib/libkse/thread/thr_join.c
+++ b/lib/libkse/thread/thr_join.c
@@ -133,6 +133,17 @@ _pthread_join(pthread_t pthread, void **thread_return)
}
THR_SCHED_UNLOCK(curthread, curthread);
+ if ((curthread->cancelflags & THR_CANCELLING) &&
+ !(curthread->cancelflags & PTHREAD_CANCEL_DISABLE)) {
+ if (_thr_ref_add(curthread, pthread, 1) == 0) {
+ THR_SCHED_LOCK(curthread, pthread);
+ pthread->joiner = NULL;
+ THR_SCHED_UNLOCK(curthread, pthread);
+ _thr_ref_delete(curthread, pthread);
+ }
+ pthread_exit(PTHREAD_CANCELED);
+ }
+
/*
* The thread return value and error are set by the
* thread we're joining to when it exits or detaches:
OpenPOWER on IntegriCloud