[Chapel Merge] Clean up uses of `pthread_once()` in the runtime.

Branch: refs/heads/main
Revision: 858aa72
Author: gbtitus
Link: Clean up uses of `pthread_once()` in the runtime. by gbtitus · Pull Request #18915 · chapel-lang/chapel · GitHub
Log Message:

Merge pull request #18915 from gbtitus/un-misuse-pthread_once

Clean up uses of pthread_once() in the runtime.

(Reviewed by @ronawho and @jhh67.)

We use pthread_once() in a number of places in the runtime. In some
cases we've been guarding it with a boolean so as to avoid calling it
when we could tell we had already done so. But in at least one of those
cases we mis-coded the guard, setting it and then assigning the set-once
value, in that order, rather than assigning the set-once value, then
doing a fence, then setting the guard. In addition, examining at least
the glibc nptl version of pthread_once() that we use on Linux systems
shows that it effectively does the same thing, using fast-path control
flow to avoid any locking when the called-once function is known to have
completed already. It seems likely that other implementations would do
similarly. Therefore here, remove all our guards on pthread_once()
calls.

Modified Files:
M runtime/src/chpl-tasks.c

M runtime/src/comm/ofi/comm-ofi.c
M runtime/src/comm/ugni/comm-ugni-heap-pages.c
M runtime/src/comm/ugni/comm-ugni.c

Compare: https://github.com/chapel-lang/chapel/compare/26ab9e1ad0fb...858aa72b11db