|
|
292b33 |
From 4da80956418bbe1fdc23cad0b1cbb24cd7b87609 Mon Sep 17 00:00:00 2001
|
|
|
292b33 |
From: =?UTF-8?q?Patrik=20H=C3=A4gglund?= <patrik.h.hagglund@ericsson.com>
|
|
|
292b33 |
Date: Sat, 2 Feb 2013 20:21:05 +0100
|
|
|
292b33 |
Subject: [PATCH] PATCH [perl #106212] Add PL_perlio_mutex to
|
|
|
292b33 |
atfork_lock/unlock
|
|
|
292b33 |
|
|
|
292b33 |
Using threads + fork() on Linux, and IO operations in the threads, the
|
|
|
292b33 |
PL_perlio_mutex may be left in a locked state at the call of fork(),
|
|
|
292b33 |
potentially leading to deadlock in the child process at subsequent IO
|
|
|
292b33 |
operations. (Threads are pre-empted and not continued in the child
|
|
|
292b33 |
process after the fork.)
|
|
|
292b33 |
|
|
|
292b33 |
Therefore, ensure that the PL_perlio_mutex is unlocked in the child
|
|
|
292b33 |
process, right after fork(), by using atfork_lock/unlock.
|
|
|
292b33 |
|
|
|
292b33 |
(The RT text gives ways to reproduce the problem, but are not easily
|
|
|
292b33 |
added to Perl's test suite)
|
|
|
292b33 |
---
|
|
|
292b33 |
util.c | 6 ++++++
|
|
|
292b33 |
1 file changed, 6 insertions(+)
|
|
|
292b33 |
|
|
|
292b33 |
diff --git a/util.c b/util.c
|
|
|
292b33 |
index 5c695b8..75381f1 100644
|
|
|
292b33 |
--- a/util.c
|
|
|
292b33 |
+++ b/util.c
|
|
|
292b33 |
@@ -2798,6 +2798,9 @@ Perl_atfork_lock(void)
|
|
|
292b33 |
dVAR;
|
|
|
292b33 |
#if defined(USE_ITHREADS)
|
|
|
292b33 |
/* locks must be held in locking order (if any) */
|
|
|
292b33 |
+# ifdef USE_PERLIO
|
|
|
292b33 |
+ MUTEX_LOCK(&PL_perlio_mutex);
|
|
|
292b33 |
+# endif
|
|
|
292b33 |
# ifdef MYMALLOC
|
|
|
292b33 |
MUTEX_LOCK(&PL_malloc_mutex);
|
|
|
292b33 |
# endif
|
|
|
292b33 |
@@ -2812,6 +2815,9 @@ Perl_atfork_unlock(void)
|
|
|
292b33 |
dVAR;
|
|
|
292b33 |
#if defined(USE_ITHREADS)
|
|
|
292b33 |
/* locks must be released in same order as in atfork_lock() */
|
|
|
292b33 |
+# ifdef USE_PERLIO
|
|
|
292b33 |
+ MUTEX_UNLOCK(&PL_perlio_mutex);
|
|
|
292b33 |
+# endif
|
|
|
292b33 |
# ifdef MYMALLOC
|
|
|
292b33 |
MUTEX_UNLOCK(&PL_malloc_mutex);
|
|
|
292b33 |
# endif
|
|
|
292b33 |
--
|
|
|
292b33 |
1.8.1.4
|
|
|
292b33 |
|