summaryrefslogtreecommitdiffstats
path: root/src/rtree.c
diff options
context:
space:
mode:
authorJason Evans <je@fb.com>2012-10-09 21:46:22 (GMT)
committerJason Evans <je@fb.com>2012-10-09 22:21:46 (GMT)
commit20f1fc95adb35ea63dc61f47f2b0ffbd37d39f32 (patch)
tree9c61145b466c8f413b4f98247f17d8509e6ed8ea /src/rtree.c
parent7de92767c20cb72c94609b9c78985526fb84a679 (diff)
downloadjemalloc-20f1fc95adb35ea63dc61f47f2b0ffbd37d39f32.zip
jemalloc-20f1fc95adb35ea63dc61f47f2b0ffbd37d39f32.tar.gz
jemalloc-20f1fc95adb35ea63dc61f47f2b0ffbd37d39f32.tar.bz2
Fix fork(2)-related deadlocks.
Add a library constructor for jemalloc that initializes the allocator. This fixes a race that could occur if threads were created by the main thread prior to any memory allocation, followed by fork(2), and then memory allocation in the child process. Fix the prefork/postfork functions to acquire/release the ctl, prof, and rtree mutexes. This fixes various fork() child process deadlocks, but one possible deadlock remains (intentionally) unaddressed: prof backtracing can acquire runtime library mutexes, so deadlock is still possible if heap profiling is enabled during fork(). This deadlock is known to be a real issue in at least the case of libgcc-based backtracing. Reported by tfengjun.
Diffstat (limited to 'src/rtree.c')
-rw-r--r--src/rtree.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/rtree.c b/src/rtree.c
index eb0ff1e..90c6935 100644
--- a/src/rtree.c
+++ b/src/rtree.c
@@ -44,3 +44,24 @@ rtree_new(unsigned bits)
return (ret);
}
+
+void
+rtree_prefork(rtree_t *rtree)
+{
+
+ malloc_mutex_prefork(&rtree->mutex);
+}
+
+void
+rtree_postfork_parent(rtree_t *rtree)
+{
+
+ malloc_mutex_postfork_parent(&rtree->mutex);
+}
+
+void
+rtree_postfork_child(rtree_t *rtree)
+{
+
+ malloc_mutex_postfork_child(&rtree->mutex);
+}