Skip to content

Commit 35fdf8d

Browse files
committed
[OpenMP] Fix a segment fault in __kmp_get_global_thread_id
In `__kmp_get_global_thread_id`, if the gtid mode is 1, after getting the gtid from TLS, it will store the gtid value to the thread stack maintained in the thread descriptor. However, `__kmp_get_global_thread_id` can be called when the library is destructed, after the corresponding thread info has been release. This will cause a segment fault. This can happen on an Intel-based Mac. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D159324
1 parent ef8121b commit 35fdf8d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

openmp/runtime/src/kmp_runtime.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ int __kmp_get_global_thread_id() {
196196
if (i < 0)
197197
return i;
198198

199+
// other_threads[i] can be nullptr at this point because the corresponding
200+
// thread could have already been destructed. It can happen when this function
201+
// is called in end library routine.
202+
if (!TCR_SYNC_PTR(other_threads[i]))
203+
return i;
204+
199205
/* dynamically updated stack window for uber threads to avoid get_specific
200206
call */
201207
if (!TCR_4(other_threads[i]->th.th_info.ds.ds_stackgrow)) {

0 commit comments

Comments
 (0)