Index: runtime/src/kmp.h =================================================================== --- runtime/src/kmp.h +++ runtime/src/kmp.h @@ -2788,6 +2788,7 @@ /* Global Locks */ extern kmp_bootstrap_lock_t __kmp_initz_lock; /* control initialization */ extern kmp_bootstrap_lock_t __kmp_forkjoin_lock; /* control fork/join access */ +extern kmp_bootstrap_lock_t __kmp_task_team_lock; extern kmp_bootstrap_lock_t __kmp_exit_lock; /* exit() is not always thread-safe */ #if KMP_USE_MONITOR @@ -2976,6 +2977,7 @@ /* read/write: lock */ extern volatile kmp_team_t *__kmp_team_pool; extern volatile kmp_info_t *__kmp_thread_pool; +extern kmp_info_t *__kmp_thread_pool_insert_pt; // total num threads reachable from some root thread including all root threads extern volatile int __kmp_nth; Index: runtime/src/kmp_itt.h =================================================================== --- runtime/src/kmp_itt.h +++ runtime/src/kmp_itt.h @@ -42,6 +42,7 @@ void __kmp_itt_initialize(); void __kmp_itt_destroy(); +void __kmp_itt_reset(); // ----------------------------------------------------------------------------- // New stuff for reporting high-level constructs. Index: runtime/src/kmp_itt.cpp =================================================================== --- runtime/src/kmp_itt.cpp +++ runtime/src/kmp_itt.cpp @@ -22,6 +22,9 @@ #if USE_ITT_NOTIFY +#include "ittnotify_config.h" +__itt_global __kmp_ittapi_clean_global; +extern __itt_global __kmp_itt__ittapi_global; kmp_int32 __kmp_barrier_domain_count; kmp_int32 __kmp_region_domain_count; __itt_domain *__kmp_itt_barrier_domains[KMP_MAX_FRAME_DOMAINS]; @@ -53,6 +56,12 @@ #endif // USE_ITT_NOTIFY +void __kmp_itt_reset() { +#if USE_ITT_NOTIFY + __kmp_itt__ittapi_global = __kmp_ittapi_clean_global; +#endif +} + void __kmp_itt_initialize() { // ITTNotify library is loaded and initialized at first call to any ittnotify @@ -60,6 +69,9 @@ // RTL version to ITTNotify. #if USE_ITT_NOTIFY + // Backup a clean global state + __kmp_ittapi_clean_global = __kmp_itt__ittapi_global; + // Report OpenMP RTL version. kmp_str_buf_t buf; __itt_mark_type version; Index: runtime/src/kmp_runtime.cpp =================================================================== --- runtime/src/kmp_runtime.cpp +++ runtime/src/kmp_runtime.cpp @@ -94,7 +94,7 @@ #endif static void __kmp_unregister_library(void); // called by __kmp_internal_end() static void __kmp_reap_thread(kmp_info_t *thread, int is_root); -static kmp_info_t *__kmp_thread_pool_insert_pt = NULL; +kmp_info_t *__kmp_thread_pool_insert_pt = NULL; /* Calculate the identifier of the current thread */ /* fast (and somewhat portable) way to get unique identifier of executing Index: runtime/src/kmp_tasking.cpp =================================================================== --- runtime/src/kmp_tasking.cpp +++ runtime/src/kmp_tasking.cpp @@ -2727,7 +2727,7 @@ static kmp_task_team_t *__kmp_free_task_teams = NULL; // Free list for task_team data structures // Lock for task team data structures -static kmp_bootstrap_lock_t __kmp_task_team_lock = +kmp_bootstrap_lock_t __kmp_task_team_lock = KMP_BOOTSTRAP_LOCK_INITIALIZER(__kmp_task_team_lock); // __kmp_alloc_task_deque: Index: runtime/src/z_Linux_util.cpp =================================================================== --- runtime/src/z_Linux_util.cpp +++ runtime/src/z_Linux_util.cpp @@ -1253,16 +1253,22 @@ #endif } -static void __kmp_atfork_prepare(void) { /* nothing to do */ +static void __kmp_atfork_prepare(void) { + __kmp_acquire_bootstrap_lock(&__kmp_initz_lock); + __kmp_acquire_bootstrap_lock(&__kmp_forkjoin_lock); } -static void __kmp_atfork_parent(void) { /* nothing to do */ +static void __kmp_atfork_parent(void) { + __kmp_release_bootstrap_lock(&__kmp_initz_lock); + __kmp_release_bootstrap_lock(&__kmp_forkjoin_lock); } /* Reset the library so execution in the child starts "all over again" with clean data structures in initial states. Don't worry about freeing memory allocated by parent, just abandon it to be safe. */ static void __kmp_atfork_child(void) { + __kmp_release_bootstrap_lock(&__kmp_initz_lock); + __kmp_release_bootstrap_lock(&__kmp_forkjoin_lock); /* TODO make sure this is done right for nested/sibling */ // ATT: Memory leaks are here? TODO: Check it and fix. /* KMP_ASSERT( 0 ); */ @@ -1307,6 +1313,10 @@ __kmp_all_nth = 0; TCW_4(__kmp_nth, 0); + __kmp_thread_pool = NULL; + __kmp_thread_pool_insert_pt = NULL; + __kmp_team_pool = NULL; + /* Must actually zero all the *cache arguments passed to __kmpc_threadprivate here so threadprivate doesn't use stale data */ KA_TRACE(10, ("__kmp_atfork_child: checking cache address list %p\n", @@ -1329,6 +1339,9 @@ __kmp_init_bootstrap_lock(&__kmp_initz_lock); __kmp_init_bootstrap_lock(&__kmp_stdio_lock); __kmp_init_bootstrap_lock(&__kmp_console_lock); + __kmp_init_bootstrap_lock(&__kmp_task_team_lock); + + __kmp_itt_reset(); // reset ITT's global state /* This is necessary to make sure no stale data is left around */ /* AC: customers complain that we use unsafe routines in the atfork