Acquire and Release Fences Don't Work the Way You'd Expect -- Jeff Preshing

The C++11 standard makes a distinction between acquire and release fences and acquire and release operations. The differences are important and can affect correctness as well as performance.

[Ed.: These correctness subtleties are another reason to avoid standalone fences... in addition to the notes in this article, there are performance reasons to do so, as mentioned in Sutter's linked talk. std::atomics are the correct tool in nearly all cases where in the past you'd have reached for a standalone fence.]

Acquire and Release Fences Don't Work the Way You'd Expect

by Jeff Preshing

From the article:

... It's perhaps surprising, then, that this definition does not apply to standalone acquire and release fences in C++11! Those are a whole other ball of wax.

To see what I mean, consider the following two code listings. They’re both taken from my post about the double-checked locking pattern in C++11. The code on the left performs a release operation directly on m_instance, while the code on the right uses a release fence instead. ...

Add a Comment

Comments are closed.

Comments (1)

1 0

squelart said on Dec 2, 2013 01:55 PM:

Link is wrong, it should be: http://preshing.com/20131125/acquire-and-release-fences-dont-work-the-way-youd-expect/