[Openmp-commits] [PATCH] D90647: [OpenMP] Fix shutdown hang bug

Jonathan Peyton via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Mon Nov 2 14:03:03 PST 2020

jlpeyton created this revision.
jlpeyton added reviewers: AndreyChurbanov, tlwilmar.
jlpeyton added a project: OpenMP.
Herald added subscribers: guansong, yaxunl.
jlpeyton requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

The deadlock happens when the primary thread gets `initz` lock and tries to join
the worker thread which waits for the same lock in TLS key destructor.
The patch removes the lock and the code of setting TLS value which needed
the lock. Also removed setting TLS from `__kmp_unregister_root_current_thread`.

  rG LLVM Github Monorepo



Index: openmp/runtime/src/kmp_runtime.cpp
--- openmp/runtime/src/kmp_runtime.cpp
+++ openmp/runtime/src/kmp_runtime.cpp
@@ -3985,12 +3985,6 @@
   __kmp_reset_root(gtid, root);
-  /* free up this thread slot */
-  __kmp_gtid_set_specific(KMP_GTID_DNE);
-  __kmp_gtid = KMP_GTID_DNE;
            ("__kmp_unregister_root_current_thread: T#%d unregistered\n", gtid));
@@ -5828,20 +5822,6 @@
   /* NOTE: the gtid is stored as gitd+1 in the thread-local-storage
    * this is because 0 is reserved for the nothing-stored case */
-  /* josh: One reason for setting the gtid specific data even when it is being
-     destroyed by pthread is to allow gtid lookup through thread specific data
-     (__kmp_gtid_get_specific).  Some of the code, especially stat code,
-     that gets executed in the call to __kmp_internal_end_thread, actually
-     gets the gtid through the thread specific data.  Setting it here seems
-     rather inelegant and perhaps wrong, but allows __kmp_internal_end_thread
-     to run smoothly.
-     todo: get rid of this after we remove the dependence on
-     __kmp_gtid_get_specific  */
-  if (gtid >= 0 && KMP_UBER_GTID(gtid))
-    __kmp_gtid_set_specific(gtid);
-  __kmp_gtid = gtid;

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90647.302401.patch
Type: text/x-patch
Size: 1415 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20201102/e9a40ca2/attachment.bin>

More information about the Openmp-commits mailing list