diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2009-02-20 01:24:06 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2009-02-20 01:24:06 +0000 |
commit | bbf4d095420ee95ad63d747c370893f32a3e570e (patch) | |
tree | df657872ac80590eb8ce99bd2a29c0d01b24a72a | |
parent | 51bf3beabc638b37b2ec30fdd35d29d75807c684 (diff) |
Fix a race in the reaper discovered by Tobias Ulmer. kevents are identified by pid,
so in the event that two threads get the same pid in a row, as the second is dying it
will update (not add) the kevent for the previous thread with its own stack, which it
will then unmap soon after, which is bad. Doing the reaping first guarantees that there
are no kevents with the same pid as the exiting thread when it registers itself.
ok guenther kurt
-rw-r--r-- | lib/librthread/rthread.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/librthread/rthread.c b/lib/librthread/rthread.c index 066d1ebd4fd..a1a76ac3fb4 100644 --- a/lib/librthread/rthread.c +++ b/lib/librthread/rthread.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread.c,v 1.39 2008/10/13 05:42:46 kevlo Exp $ */ +/* $OpenBSD: rthread.c,v 1.40 2009/02/20 01:24:05 tedu Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -218,10 +218,11 @@ pthread_exit(void *retval) _sem_post(&thread->donesem); } + /* reap before adding self, we don't want to disappear too soon */ + _rthread_reaper(); if (tid != _initial_thread.tid) _rthread_add_to_reaper(tid, stack); - _rthread_reaper(); threxit(0); for(;;); } |