[all-commits] [llvm/llvm-project] ff5c72: [OpenMP] Fix a wrong assertion in `__kmp_get_globa...

Shilei Tian via All-commits all-commits at lists.llvm.org
Wed Sep 6 09:21:57 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: ff5c7261ef01393acad207a10b6ea8fd579206ef
      https://github.com/llvm/llvm-project/commit/ff5c7261ef01393acad207a10b6ea8fd579206ef
  Author: Shilei Tian <i at tianshilei.me>
  Date:   2023-09-06 (Wed, 06 Sep 2023)

  Changed paths:
    M openmp/runtime/src/kmp_runtime.cpp

  Log Message:
  -----------
  [OpenMP] Fix a wrong assertion in `__kmp_get_global_thread_id`

The function assumes that `__kmp_gtid_get_specific` always returns a valid gtid.
That is not always true, because when creating the key for thread-specific data,
a destructor is assigned. The dtor will be called at thread exit. However, before
the dtor is called, the thread-specific data will be reset to NULL first
(https://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_key_create.html):

> At thread exit, if a key value has a non-NULL destructor pointer, and the thread
> has a non-NULL value associated with that key, the value of the key is set to NULL.

This will lead to that `__kmp_gtid_get_specific` returns `KMP_GTID_DNE`.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D159369




More information about the All-commits mailing list