Module Name:    src
Committed By:   enami
Date:           Thu Apr 26 00:21:44 UTC 2012

Modified Files:
        src/lib/libpthread: pthread.c

Log Message:
Store allocated lwpctl state in the thread actually forked,
which is the only thread lives in the child process.

The problem originally reported here:
  https://bugs.ruby-lang.org/issues/6341


To generate a diff of this commit:
cvs rdiff -u -r1.133 -r1.134 src/lib/libpthread/pthread.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libpthread/pthread.c
diff -u src/lib/libpthread/pthread.c:1.133 src/lib/libpthread/pthread.c:1.134
--- src/lib/libpthread/pthread.c:1.133	Thu Mar 22 20:01:18 2012
+++ src/lib/libpthread/pthread.c	Thu Apr 26 00:21:44 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.133 2012/03/22 20:01:18 drochner Exp $	*/
+/*	$NetBSD: pthread.c,v 1.134 2012/04/26 00:21:44 enami Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread.c,v 1.133 2012/03/22 20:01:18 drochner Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.134 2012/04/26 00:21:44 enami Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -84,7 +84,6 @@ pthread_queue_t pthread__allqueue;
 
 static pthread_attr_t pthread_default_attr;
 static lwpctl_t pthread__dummy_lwpctl = { .lc_curcpu = LWPCTL_CPU_NONE };
-static pthread_t pthread__first;
 
 enum {
 	DIAGASSERT_ABORT =	1<<0,
@@ -229,7 +228,6 @@ pthread__init(void)
 	}
 
 	/* Tell libc that we're here and it should role-play accordingly. */
-	pthread__first = first;
 	pthread_atfork(NULL, NULL, pthread__fork_callback);
 	__isthreaded = 1;
 }
@@ -237,13 +235,12 @@ pthread__init(void)
 static void
 pthread__fork_callback(void)
 {
-	struct __pthread_st *self;
+	struct __pthread_st *self = pthread__self();
 
 	/* lwpctl state is not copied across fork. */
-	if (_lwp_ctl(LWPCTL_FEATURE_CURCPU, &pthread__first->pt_lwpctl)) {
+	if (_lwp_ctl(LWPCTL_FEATURE_CURCPU, &self->pt_lwpctl)) {
 		err(1, "_lwp_ctl");
 	}
-	self = pthread__self();
 	self->pt_lid = _lwp_self();
 }
 

Reply via email to