Open gbaraldi opened 3 months ago
libc uses a relaxed load https://github.com/llvm/llvm-project/blob/95820ca263cf1f6369928782882c2fd13633a7e9/libc/src/__support/threads/linux/callonce.h#L26-L28 while libcpp uses acquire https://github.com/llvm/llvm-project/blob/95820ca263cf1f6369928782882c2fd13633a7e9/libcxx/include/__mutex/once_flag.h#L127
A relaxed load has no ordering constraints so if one thread calls pthread_once and another goes through the fast path, even if the other thread observes the FINISH value. What guarantees that the side effects are visible from it?
FINISH
cc @SchrodingerZhu we can change llvm-libc to match libc++.
libc uses a relaxed load https://github.com/llvm/llvm-project/blob/95820ca263cf1f6369928782882c2fd13633a7e9/libc/src/__support/threads/linux/callonce.h#L26-L28 while libcpp uses acquire https://github.com/llvm/llvm-project/blob/95820ca263cf1f6369928782882c2fd13633a7e9/libcxx/include/__mutex/once_flag.h#L127
A relaxed load has no ordering constraints so if one thread calls pthread_once and another goes through the fast path, even if the other thread observes the
FINISH
value. What guarantees that the side effects are visible from it?