From fe5567c8f172d8218fb37af60118825748628d44 Mon Sep 17 00:00:00 2001 From: davidxu Date: Sun, 19 Sep 2010 09:03:11 +0000 Subject: Because atfork lock is held while forking, a thread cancellation triggered by atfork handler is unsafe, use intenal flag no_cancel to disable it. --- lib/libthr/thread/thr_fork.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib/libthr/thread/thr_fork.c') diff --git a/lib/libthr/thread/thr_fork.c b/lib/libthr/thread/thr_fork.c index dd6005a..fb5daa1 100644 --- a/lib/libthr/thread/thr_fork.c +++ b/lib/libthr/thread/thr_fork.c @@ -137,7 +137,7 @@ _fork(void) struct pthread *curthread; struct pthread_atfork *af; pid_t ret; - int errsave; + int errsave, cancelsave; int was_threaded; int rtld_locks[MAX_RTLD_LOCKS]; @@ -145,7 +145,8 @@ _fork(void) return (__sys_fork()); curthread = _get_curthread(); - + cancelsave = curthread->no_cancel; + curthread->no_cancel = 1; _thr_rwl_rdlock(&_thr_atfork_lock); /* Run down atfork prepare handlers. */ @@ -223,6 +224,7 @@ _fork(void) af->child(); } _thr_rwlock_unlock(&_thr_atfork_lock); + curthread->no_cancel = cancelsave; } else { /* Parent process */ errsave = errno; @@ -244,6 +246,9 @@ _fork(void) } _thr_rwlock_unlock(&_thr_atfork_lock); + curthread->no_cancel = cancelsave; + /* test async cancel */ + _thr_testcancel(curthread); } errno = errsave; -- cgit v1.1