Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
document that we really need xbt_os_thread_atfork (for tesh+mmalloc)
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 16 Oct 2012 20:04:22 +0000 (22:04 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 16 Oct 2012 20:04:22 +0000 (22:04 +0200)
include/xbt/xbt_os_thread.h
src/xbt/mmalloc/mm_module.c
src/xbt/xbt_os_thread.c

index 31e5840..866958a 100644 (file)
@@ -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),
index 06f6266..cd4ef27 100644 (file)
@@ -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);
index e18ae2e..08e82d5 100644 (file)
@@ -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))
 {