多线程课程001:线程安全的问题
下面的做法,会发现输出结果被打断了。
main应该执行完10次才到sub的,可是被打断了main thread sequence of 98,loop of 32main thread sequence of 99,loop of 32main thread sequence of 100,loop of 32sub thread sequence of 1,loop of 33sub thread sequence of 2,loop of 33sub thread sequence of 3,loop of 33sub thread sequence of 4,loop of 33sub thread sequence of 5,loop of 33sub thread sequence of 6,loop of 33sub thread sequence of 7,loop of 33sub thread sequence of 8,loop of 33sub thread sequence of 9,loop of 33sub thread sequence of 10,loop of 33main thread sequence of 1,loop of 33main thread sequence of 2,loop of 33