Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libpthread Make pthread_join() accomodate spurious wakeu...
details: https://anonhg.NetBSD.org/src/rev/3047c6558547
branches: trunk
changeset: 542268:3047c6558547
user: nathanw <nathanw%NetBSD.org@localhost>
date: Sat Jan 25 00:37:01 2003 +0000
description:
Make pthread_join() accomodate spurious wakeups from pthread__block().
diffstat:
lib/libpthread/pthread.c | 26 ++++++++++++++++----------
1 files changed, 16 insertions(+), 10 deletions(-)
diffs (54 lines):
diff -r 9f0ab77f0599 -r 3047c6558547 lib/libpthread/pthread.c
--- a/lib/libpthread/pthread.c Sat Jan 25 00:17:30 2003 +0000
+++ b/lib/libpthread/pthread.c Sat Jan 25 00:37:01 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread.c,v 1.5 2003/01/19 21:58:24 thorpej Exp $ */
+/* $NetBSD: pthread.c,v 1.6 2003/01/25 00:37:01 nathanw Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -415,6 +415,7 @@
pthread_join(pthread_t thread, void **valptr)
{
pthread_t self;
+ int num;
self = pthread__self();
SDPRINTF(("(pthread_join %p) Joining %p.\n", self, thread));
@@ -435,8 +436,20 @@
return EINVAL;
}
- if ((thread->pt_state != PT_STATE_ZOMBIE) &&
- (thread->pt_state != PT_STATE_DEAD)) {
+ num = thread->pt_num;
+ while (thread->pt_state != PT_STATE_ZOMBIE) {
+ if ((thread->pt_state == PT_STATE_DEAD) ||
+ (thread->pt_flags & PT_FLAG_DETACHED) ||
+ (thread->pt_num != num)) {
+ /*
+ * Another thread beat us to the join, or called
+ * pthread_detach(). If num didn't match, the
+ * thread died and was recycled before we got
+ * another chance to run.
+ */
+ pthread_spinunlock(self, &thread->pt_join_lock);
+ return ESRCH;
+ }
/*
* "I'm not dead yet!"
* "You will be soon enough."
@@ -458,13 +471,6 @@
pthread_spinlock(self, &thread->pt_join_lock);
}
- if ((thread->pt_state == PT_STATE_DEAD) ||
- (thread->pt_flags & PT_FLAG_DETACHED)) {
- /* Someone beat us to the join, or called pthread_detach(). */
- pthread_spinunlock(self, &thread->pt_join_lock);
- return ESRCH;
- }
-
/* All ours. */
thread->pt_state = PT_STATE_DEAD;
pthread_spinunlock(self, &thread->pt_join_lock);
Home |
Main Index |
Thread Index |
Old Index