You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
你是?要是真想问东西扣扣问别发邮件邮件不会回的------------------ 原始邮件 ------------------
发件人: "chsobin"<[email protected]>
发送时间: 2019年8月4日(星期天) 凌晨0:53
收件人: "crossoverJie/JCSprout"<[email protected]>;
抄送: "Subscribed"<[email protected]>;
主题: Re: [crossoverJie/JCSprout] 交替打印奇偶数,控制输出到1000,但是经过测试发现有时会输出到1001 (#165)
改进思路:
可以参考Double Check机制
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
代码地址
运行结果:
分析
1、当奇数线程在箭头处发生上下文切换
2、偶数线程获取锁,输出1000,并将number.start加为1001,释放锁,判断1001>1000,线程结束
3、奇数线程恢复执行,就会输出1001
The text was updated successfully, but these errors were encountered: