On Tue, Nov 05, 2024 at 12:30:39PM -0600, Haris Okanovic wrote: > + do { > + cur = __READ_ONCE_EX(*addr); > + if ((cur & mask) == val) { > + break; > + } > wfet(end); Constructs like this need to be entirely in assembly. The compiler may spill 'cur' onto the stack and the write could clear the exclusive monitor which makes the wfet return immediately. That's highly CPU implementation specific but it's the reason we have functions like __cmpwait() in assembly (or whatever else deals with exclusives). IOW, we can't have other memory accesses between the LDXR and whatever is consuming the exclusive monitor armed state (typically STXR but WFE/WFET can be another). -- Catalin