Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In C++, which Standard Library functions (if any) are required to implicitly provided an atomic memory fence?

For example, is calling std::mutex::lock() required by the Standard to provide a sequentially consistent fence, an acquire fence, or neither?

cppreference.com doesn't seem to address this topic. Is it addressed in any reference documentation that's more easy to use than the Standard or working papers?

like image 977
WaltK Avatar asked Sep 03 '25 09:09

WaltK


1 Answers

I'm not sure about an easier source, but here's a quote from a note in the standard:

[...] a call that acquires a mutex will perform an acquire operation on the locations comprising the mutex. Correspondingly, a call that releases the same mutex will perform a release operation on those same locations. Informally, performing a release operation on A forces prior side effects on other memory locations to become visible to other threads that later perform a consume or an acquire operation on A.

I think that answers the question about memory fences reasonably well (and although it's "only" a note, not a normative part of the standard, I'd say it's as reliable a description of the standard as any other site could hope to provide).

like image 111
Jerry Coffin Avatar answered Sep 05 '25 00:09

Jerry Coffin