diff --git a/openmp/runtime/src/kmp_runtime.cpp b/openmp/runtime/src/kmp_runtime.cpp --- a/openmp/runtime/src/kmp_runtime.cpp +++ b/openmp/runtime/src/kmp_runtime.cpp @@ -178,7 +178,12 @@ if (stack_diff <= stack_size) { /* The only way we can be closer than the allocated */ /* stack size is if we are running on this thread. */ - KMP_DEBUG_ASSERT(__kmp_gtid_get_specific() == i); + // __kmp_gtid_get_specific can return KMP_GTID_DNE because this function + // can be called by thread destructor. However, before the thread + // destructor is called, the value of the corresponding thread-specific + // data will be reset to NULL. + KMP_DEBUG_ASSERT(__kmp_gtid_get_specific() == KMP_GTID_DNE || + __kmp_gtid_get_specific() == i); return i; } }