-
参考资料:
- jsr133文档
- ansi-iso-9899-1990 (C89标准)
- 参考链接:
- 代码环境:
- C语言:gcc (x86_64-win32-seh-rev0, Built by MinGW-W64 project) 8.1.0 Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- Java: openjdk version "1.8.0_333" OpenJDK Runtime Environment (build 1.8.0_333-b02) OpenJDK 64-Bit Server VM (build 25.333-b02, mixed mode)
- 其它注意说明:C语言线程一代码里的空循环是为了“等待”线程二,在测试时,有时我几百次就能观察到指令重排,有时候几十万次才能观察到,很大一部分原因是因为线程一先启动,线程二后启动,所以要调节这里空循环的次数,让两个线程尽量做到同时启动,还有,运行代码时最好关闭优化,因为编译器可能会将这行空循环代码给优化掉,最后,运行C语言文件时候别忘了动态链接 -lpthread
截图说明:
- JSR文档对volatile语义增强