这是另一个question of mine的跟进.
@templatetypedef回答了问题(赞赏),他在回答中写道:
As a note – atomicity does not mean “all other threads will be blocked
until the value is ready. It means all other threads will either see
the state purely before the operation is done or purely after the
operation is done, but nothing else.
我对此感到困惑,原因如下:
Atomic actions cannot be interleaved, so they can be used without fear
of thread interference.
我从中推断出的是,这与他的著作相矛盾.
如果我们有2个int变量i1和i2,我们执行原子操作i1 = i2;并且此操作由threadX执行.
然后,如果无法按上述方式交错原子操作,则意味着在此原子操作(由threadX执行)期间,不允许其他线程Y访问(用于读取或写入)相同的变量i2,因此,其他线程Y不被访问.允许在原子操作期间访问相同的变量,因此确实存在某种形式的阻塞.
我说对了吗?
谢谢…