New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
交替打印奇偶数,控制输出到1000,但是经过测试发现有时会输出到1001 #165
Comments
你是?要是真想问东西扣扣问别发邮件邮件不会回的------------------ 原始邮件 ------------------
发件人: "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.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
代码地址
运行结果:
分析
1、当奇数线程在箭头处发生上下文切换
2、偶数线程获取锁,输出1000,并将number.start加为1001,释放锁,判断1001>1000,线程结束
3、奇数线程恢复执行,就会输出1001
The text was updated successfully, but these errors were encountered: