Scott Peterson
Scott Peterson

Reputation: 149

Are there cases where either an Acquire or Release barrier occurs by itself without the other matching barrier?

Is it necessary to always pair the Acquire and Release barriers? Are there any genuine cases where one may occur without the corresponding pair (including full memory barriers which satisfy both)? I know that the C++11 memory model states that such unpaired programs are not Data Race Free, but is this always the case?

For example, the linux kernel's documentation on memory barriers states:

An ACQUIRE operation should almost always be paired with a RELEASE operation.

Why does it say "almost always" and not "always"?

Upvotes: 3

Views: 217

Answers (2)

Yurii Romanchenko
Yurii Romanchenko

Reputation: 848

If I correctly understand dispatch_once source code omits read-acquire barrier in performance purposes.

You can find more information in this blog

Upvotes: 0

MSalters
MSalters

Reputation: 179819

A typical edge case is when you have 2 ACQUIRE's that match a single RELEASE. Not strictly paired, but this may simplify some code flow where otherwise you'd need to keep flags saying an ACQUIRE is pending.

Upvotes: 1

Related Questions