From f9a6652301a5b9708bd74a7fc7e9ae57f26d36f8 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 16 Oct 2012 22:04:22 +0200 Subject: [PATCH] document that we really need xbt_os_thread_atfork (for tesh+mmalloc) --- include/xbt/xbt_os_thread.h | 7 +++++-- src/xbt/mmalloc/mm_module.c | 4 +++- src/xbt/xbt_os_thread.c | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/xbt/xbt_os_thread.h b/include/xbt/xbt_os_thread.h index 31e5840049..866958a634 100644 --- a/include/xbt/xbt_os_thread.h +++ b/include/xbt/xbt_os_thread.h @@ -33,8 +33,11 @@ typedef DWORD xbt_os_thread_key_t; typedef pthread_key_t xbt_os_thread_key_t; #endif -/* Calls pthread_atfork() if present, and else does nothing. - * The only known user of this wrapper is mmalloc_preinit(); This function may disapear in the near future. +/** Calls pthread_atfork() if present, and raise an exception otherwise. + * + * The only known user of this wrapper is mmalloc_preinit(), but it is absolutely mandatory there: + * when used with tesh, mmalloc *must* be mutex protected and resistant to forks. + * This functionality is the only way to get it working (by ensuring that the mutex is consistently released on forks) */ XBT_PUBLIC(int) xbt_os_thread_atfork(void (*prepare)(void), void (*parent)(void), diff --git a/src/xbt/mmalloc/mm_module.c b/src/xbt/mmalloc/mm_module.c index 06f6266191..cd4ef278da 100644 --- a/src/xbt/mmalloc/mm_module.c +++ b/src/xbt/mmalloc/mm_module.c @@ -321,7 +321,9 @@ void *mmalloc_preinit(void) void *addr = (void*)(((unsigned long)sbrk(0) + HEAP_OFFSET) & mask); __mmalloc_default_mdp = xbt_mheap_new(-1, addr); /* Fixme? only the default mdp in protected against forks */ - res = xbt_os_thread_atfork(mmalloc_fork_prepare, //FIXME: KILLME when things settle a bit + // This is mandated to protect the mmalloced areas through forks. Think of tesh. + // Nah, removing the mutex isn't a good idea either for tesh + res = xbt_os_thread_atfork(mmalloc_fork_prepare, mmalloc_fork_parent, mmalloc_fork_child); if (res != 0) THROWF(system_error,0,"xbt_os_thread_atfork() failed: return value %d",res); diff --git a/src/xbt/xbt_os_thread.c b/src/xbt/xbt_os_thread.c index e18ae2ef2a..08e82d5563 100644 --- a/src/xbt/xbt_os_thread.c +++ b/src/xbt/xbt_os_thread.c @@ -133,6 +133,7 @@ void xbt_os_thread_mod_postexit(void) __xbt_ex_terminate = &__xbt_ex_terminate_default; } +/* this function is critical to tesh+mmalloc, don't mess with it */ int xbt_os_thread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void)) { -- 2.20.1