Module Name: src
Committed By: joerg
Date: Wed Dec 25 00:44:45 UTC 2019
Modified Files:
src/lib/libpthread: pthread_tsd.c
Log Message:
Since pthread_setspecific requires locks, ensure that they are acquired
before fork and dropped in both parent and child. At least Python
depends on TSD after fork, even though it is undefined behavior in
POSIX.
To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/lib/libpthread/pthread_tsd.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_tsd.c
diff -u src/lib/libpthread/pthread_tsd.c:1.17 src/lib/libpthread/pthread_tsd.c:1.18
--- src/lib/libpthread/pthread_tsd.c:1.17 Tue Mar 5 01:35:52 2019
+++ src/lib/libpthread/pthread_tsd.c Wed Dec 25 00:44:45 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_tsd.c,v 1.17 2019/03/05 01:35:52 christos Exp $ */
+/* $NetBSD: pthread_tsd.c,v 1.18 2019/12/25 00:44:45 joerg Exp $ */
/*-
* Copyright (c) 2001, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_tsd.c,v 1.17 2019/03/05 01:35:52 christos Exp $");
+__RCSID("$NetBSD: pthread_tsd.c,v 1.18 2019/12/25 00:44:45 joerg Exp $");
/* Functions and structures dealing with thread-specific data */
#include <errno.h>
@@ -61,6 +61,18 @@ null_destructor(void *p)
#include <stdlib.h>
#include <stdio.h>
+static void
+pthread_tsd_prefork(void)
+{
+ pthread_mutex_lock(&tsd_mutex);
+}
+
+static void
+pthread_tsd_postfork(void)
+{
+ pthread_mutex_unlock(&tsd_mutex);
+}
+
void *
pthread_tsd_init(size_t *tlen)
{
@@ -68,6 +80,8 @@ pthread_tsd_init(size_t *tlen)
size_t alen;
char *arena;
+ pthread_atfork(pthread_tsd_prefork, pthread_tsd_postfork, pthread_tsd_postfork);
+
if ((pkm = pthread__getenv("PTHREAD_KEYS_MAX")) != NULL) {
pthread_keys_max = (int)strtol(pkm, NULL, 0);
if (pthread_keys_max < _POSIX_THREAD_KEYS_MAX)