This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP] Fix a wrong assertion in `__kmp_get_global_thread_id`
ClosedPublic

Authored by tianshilei1992 on Sep 1 2023, 10:32 AM.

Details

Summary

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.

Diff Detail

Event Timeline

tianshilei1992 created this revision.Sep 1 2023, 10:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 1 2023, 10:32 AM
tianshilei1992 requested review of this revision.Sep 1 2023, 10:32 AM
Herald added a project: Restricted Project. · View Herald Transcript

This also fixes the issue introduced by D41167, which causes a test failure on Intel-based macOS.

make it cleaner

Can we check if it's i or KMP_GTID_DNE instead?

make it clear

jdoerfert accepted this revision.Sep 5 2023, 9:44 PM
This revision is now accepted and ready to land.Sep 5 2023, 9:44 PM