weixin_41335120
2018-03-14 04:35
采纳率: 81.8%
浏览 771
已采纳

volatile 关键字的一个题目

public volatile long shared;
and assume further that thread t1 is trying to assign value v1 to shared while t2
is trying to assign it value v2. Is it guaranteed that shared will wind up with either v1
or v2 when the threads finish? Explain.
题目是说看上面那个code,Thread 1 试着给他赋值 v1,Thread 2也试着给他赋值 v2,那两个线程运行结束后,shared 值是不是一定是v1或者v2,为什么?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新