Skip to content

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

@gbaraldi

Description

@gbaraldi

libc uses a relaxed load

LIBC_INLINE bool callonce_fastpath(CallOnceFlag *flag) {
return flag->load(cpp::MemoryOrder::RELAXED) == FINISH;
}
while libcpp uses acquire
if (__libcpp_acquire_load(&__flag.__state_) != once_flag::_Complete) {

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions