yohhoyの日記

技術的メモをしていきたい日記

lock-freeとaddress-free

C++11標準ライブラリにおけるatomic変数のロックフリー(lock-free)に関連して、規格中で言及されている "address-free" についてメモ。

N3337 29.4/p3より引用。

[Note: Operations that are lock-free should also be address-free. That is, atomic operations on the same memory location via two different addresses will communicate atomically. The implementation should not depend on any per-process state. This restriction enables communication by memory that is mapped into a process more than once and by memory that is shared between two processes. -- end note]

N2427 "C++ Atomic Types and Operations"のDiscussion of Designに関連記述あり。

Lock-Free Property
(snip)
To facilitate inter-process communication via shared memory, it is our intent that lock-free operations also be address-free. That is, atomic operations on the same memory location via two different addresses will communicate atomically. The implementation shall not depend on any per-process state. While such a definition is beyond the scope of the standard, a clear statement of our intent will enable a portable expression of class of a programs already extant.

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2427.html

本来はC++標準規格が定める範囲を超えるが、ロックフリー操作可能なatomic変数によるプロセス間通信を考慮している。共有メモリ上に存在する1つのatomic変数が、それぞれのプロセス上で異なるアドレスに割り当てられる場合でも、同変数に対してatomicに操作を行えるべきと言及している(address-free=変数のアドレス値に依存しない)。