[Openmp-commits] [openmp] r259037 - [OMPT] Avoid SEGV when a worker thread needs its parallel id behind the barrier

Jonas Hahnfeld via Openmp-commits openmp-commits at lists.llvm.org
Thu Jan 28 02:39:45 PST 2016


Author: hahnfeld
Date: Thu Jan 28 04:39:45 2016
New Revision: 259037

URL: http://llvm.org/viewvc/llvm-project?rev=259037&view=rev
Log:
[OMPT] Avoid SEGV when a worker thread needs its parallel id behind the barrier

When the code behind the barrier is executed, the master thread may have
already resumed execution. That's why we cannot safely assume that *pteam
is not yet freed.

This has been introduced by r258866.

Modified:
    openmp/trunk/runtime/src/kmp_runtime.c

Modified: openmp/trunk/runtime/src/kmp_runtime.c
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_runtime.c?rev=259037&r1=259036&r2=259037&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_runtime.c (original)
+++ openmp/trunk/runtime/src/kmp_runtime.c Thu Jan 28 04:39:45 2016
@@ -5504,8 +5504,10 @@ __kmp_launch_thread( kmp_info_t *this_th
         if ( TCR_SYNC_PTR(*pteam) && !TCR_4(__kmp_global.g.g_done) ) {
 #if OMPT_SUPPORT
             ompt_task_info_t *task_info;
+            ompt_parallel_id_t my_parallel_id;
             if (ompt_enabled) {
                 task_info = __ompt_get_taskinfo(0);
+                my_parallel_id = (*pteam)->t.ompt_team_info.parallel_id;
             }
 #endif
             /* we were just woken up, so run our new task */
@@ -5550,7 +5552,8 @@ __kmp_launch_thread( kmp_info_t *this_th
 #if OMPT_SUPPORT && OMPT_TRACE
             if (ompt_enabled) {
                 if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)) {
-                    int my_parallel_id = (*pteam)->t.ompt_team_info.parallel_id;
+                    // don't access *pteam here: it may have already been freed
+                    // by the master thread behind the barrier (possible race)
                     ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)(
                         my_parallel_id, task_info->task_id);
                 }




More information about the Openmp-commits mailing list