# CLR 2.0 Memory Model

 CacheTemp = Inited Rv = Value Ri = CacheTemp 

1. 当线程隔离运行时，行为不会改变。它的意思是，指定线程到指定位置的读或写操作不会通过相同的线程到相同位置的写操作。
2. 读操作在获得锁时，数据不能移动。
3. 写操作在释放锁时，数据不能移动。

1. 在volatile读前，读操作和写操作都不能移动数据。
2. 在volatile写后，读操作和写操作都不能移动数据。

1. A write can only move later in time.
2. A write cannot move past another write from the same thread.
3. A write cannot move past a read from the same thread to the same location.
4. A read can only move by going later in time to stay after a write to keep from breaking rule 3 as that write moves later in time.

1. All the rules that are contained in the ECMA model, in particular the three fundamental memory model rules as well as the ECMA rules for volatile.
2. Reads and writes cannot be introduced.
3. A read can only be removed if it is adjacent to another read to the same location from the same thread. A write can only be removed if it is adjacent to another write to the same location from the same thread. Rule 5 can be used to make reads or writes adjacent before applying this rule.
4. Writes cannot move past other writes from the same thread.
5. Reads can only move earlier in time, but never past a write to the same memory location from the same thread.

Lock-Free

1. Data dependence among loads and stores is never violated.
2. All stores have release semantics, i.e. no load or store may move after one.
3. All volatile loads are acquire, i.e. no load or store may move before one.
4. No loads and stores may ever cross a full-barrier (e.g. Thread.MemoryBarrier, lock acquire, Interlocked.Exchange, Interlocked.CompareExchange, etc.).
5. Loads and stores to the heap may never be introduced.
6. Loads and stores may only be deleted when coalescing adjacent loads and stores from/to the same location.

posted @ 2008-03-16 15:16 Angel Lucifer 阅读(...) 评论(...) 编辑 收藏