clarkli 发表于 30-6-2016 22:58
因为x和y都是true,所以++z执行了两次?
DDD888 发表于 1-7-2016 06:28
They are running in multiple threads, the order is not controlled. If they are running in single t ...
clarkli 发表于 1-7-2016 21:17
所以看缘分,我在VM里面跑的结果大部分是1,偶尔是2
clarkli 发表于 2-7-2016 12:41
和操作系统线程调度有关。
换台电脑,或者换个系统结果可能就不一样了。这个代码是不能在生产中用的
DDD888 发表于 2-7-2016 16:12
The trouble for me is that I do not understand that source code.
I understand following code ...
clarkli 发表于 3-7-2016 18:45
不理解为什么输出2还是不理解为什么那样写?
DDD888 发表于 3-7-2016 18:54
不理解为什么输出2
clarkli 发表于 3-7-2016 23:13
执行顺序可能是:
write_x(); // x is now true
write_y(); // y is now true
clarkli 发表于 4-7-2016 21:11
不会,++z至少会被执行一次
clarkli 发表于 5-7-2016 20:08
以read_x_then_y()为例
++z不被执行的唯一可能情况是x == true && y == false,而一旦x为true,read_y_t ...
欢迎光临 FreeOZ论坛 (https://www.freeoz.org/bbs/) | Powered by Discuz! X3.2 |