- 论坛徽章:
- 0
|
似乎是这样, 但那个volatile的顺序保证那句话, 我还晕着呢, 不知道保证的是volatile变量之间的顺序, ...
zylthinking 发表于 2011-10-18 16:26 ![]()
可能不完全是volatile, msdn中提到全局和静态变量:
when optimizing, the compiler must maintain ordering among references to volatile objects as well as references to other global objects. In particular,
A write to a volatile object (volatile write) has Release semantics; a reference to a global or static object that occurs before a write to a volatile object in the instruction sequence will occur before that volatile write in the compiled binary.
A read of a volatile object (volatile read) has Acquire semantics; a reference to a global or static object that occurs after a read of volatile memory in the instruction sequence will occur after that volatile read in the compiled binary.
This allows volatile objects to be used for memory locks and releases in multithreaded applications. |
|