llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.3k stars 12.11k forks source link

Fast path memory ordering is inconsistent between libcpp and libc #102656

Open gbaraldi opened 3 months ago

gbaraldi commented 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?

nickdesaulniers commented 1 month ago

cc @SchrodingerZhu we can change llvm-libc to match libc++.