Commit Diff


commit - 5f4529e351e77e4ab61d258ca3dea69852a1e0ba
commit + 9689b580bdb168b87a20a5e466864337d591acfa
blob - 0bc19057fb6ef319f3172b60b2e77da5e298cbb5
blob + 8090ea59c428d62d07e2926bfe101693bf99d40f
--- src/libthread/BSD.c
+++ src/libthread/BSD.c
@@ -284,6 +284,20 @@ threadexitsall(char *msg)
 	static int pid[1024];
 	int i, npid, mypid;
 	Proc *p;
+
+	/* 
+	 * Only one guy, ever, gets to run this.
+	 * If two guys do it, inevitably they end up
+	 * tripping over each other in the underlying
+	 * C library exit() implementation, which is
+	 * trying to run the atexit handlers and apparently
+	 * not thread safe.  This has been observed on
+	 * both Linux and OpenBSD.  Sigh.
+	 */
+	{
+		static Lock onelock;
+		lock(&onelock);
+	}
 
 	if(msg == nil)
 		msg = "";
blob - f741a03ddb1a11121a142ffc9da82b2c13f7d01e
blob + 146988562391981e2d38f1cf852222eefb45ac16
--- src/libthread/Linux.c
+++ src/libthread/Linux.c
@@ -310,6 +310,20 @@ threadexitsall(char *msg)
 	static int pid[1024];
 	int i, npid, mypid;
 	Proc *p;
+
+	/* 
+	 * Only one guy, ever, gets to run this.
+	 * If two guys do it, inevitably they end up
+	 * tripping over each other in the underlying
+	 * C library exit() implementation, which is
+	 * trying to run the atexit handlers and apparently
+	 * not thread safe.  This has been observed on
+	 * both Linux and OpenBSD.  Sigh.
+	 */
+	{
+		static Lock onelock;
+		lock(&onelock);
+	}
 
 	if(msg == nil)
 		msg = "";