Fix re-locking hang found in issue 86684 #88539
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This was initially reported here (including stacktraces): https://stackoverflow.com/questions/78183545/does-compiling-imagick-with-openmp-enabled-in-freebsd-13-2-cause-sched-yield
If
__kmp_register_library_startup()
detects that another instance of the library is present,__kmp_is_address_mapped()
is eventually called. which useskmpc_alloc()
to allocate memory. This function calls__kmp_entry_thread()
to access the thread-local memory pool, which is a bad idea during initialization. This macro internally calls__kmp_get_global_thread_id_reg()
which sets the bootstrap lock at the beginning (before calling__kmp_register_library_startup()
).The fix is to use
KMP_INTERNAL_MALLOC()
/KMP_INTERNAL_FREE()
instead ofkmpc_malloc()
/kmpc_free()
.KMP_INTERNAL_MALLOC
andKMP_INTERNAL_FREE
do not use any bootstrap locks. They just translate tomalloc()
/free()
and are meant to be used during library initialization before other library-specific allocators have been initialized.Fixes: #86684