What is Acquire-release semantics?
An ordering guarantee: operations after an acquire cannot move before it, and operations before a release cannot move after it. Used for lock acquire and release, it is lighter than a full barrier.
Field: Multicore & Synchronization
Japanese name: アクワイア・リリース
What it guarantees
Compilers and processors reorder memory reads and writes as long as the result of a single thread is unchanged. If reordering moves an operation inside a lock-protected region to outside the lock, the protection is meaningless. The acquire guarantee is that operations written after the acquire do not move before it. The release guarantee is that operations written before the release do not move after it. Together they keep the contents of the protected region from escaping. Operations outside are allowed to move in, so this is lighter than a full barrier, which blocks both directions.
Use with atomic variables
Programs that use no locks use the same guarantees. After preparing data, a thread writes to a variable that signals readiness, with the release ordering. The receiving thread reads that variable with the acquire ordering. If it sees that the data is ready, it is guaranteed to see the data written before the signal. Without these orderings, the variable may indicate readiness while the data still appears stale.
Differences between processors
x86 processors reorder memory operations little to begin with, and ordinary reads and writes satisfy these guarantees, so no extra instructions are needed. Arm and RISC-V allow more reordering and need dedicated instructions or light barriers. A program with incorrect orderings can therefore run without trouble on x86 and malfunction when moved to Arm.
Try it: questions about Acquire-release semantics
- ABoth acquire and release are the heaviest barriers, completely stopping all reads and writes
- BAcquire allocates memory and release frees it
- CReads and writes after an acquire cannot move before it, and reads and writes before a release cannot move after it
Show answer and explanation
Answer: C. Reads and writes after an acquire cannot move before it, and reads and writes before a release cannot move after it
Taking a lock has acquire semantics and releasing it has release semantics. Operations after the acquire do not leak to before the lock is taken, and operations before the release do not leak to after it is released, so accesses in the protected region stay inside it. With fewer restrictions than a full barrier, which blocks both directions, hardware can keep the remaining reorderings for performance.
FAQ
Is it safe always to use the strongest ordering?
As far as correctness goes, yes. The usual approach is to write with the strongest ordering first and weaken it, after careful thought, only where performance proves to be a problem.
How does it differ from the ordering that guarantees nothing about order?
That ordering guarantees only that the read or write of the variable itself is not torn. It guarantees nothing about order relative to other variables. It is used where no other data is involved, as with a simple counter.
Books on Multicore & Synchronization Ad
As an Amazon Associate I earn from qualifying purchases.
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.
Back to the glossary