“我认为是线程2的步骤A覆盖了线呈1的AB步骤,而线程2的C步骤又取代了线程1的C步骤
(就是说线程1的C步骤本来是把1100赋给salary的,可是实际上是1200赋给了salary)”对呀,线程2的步骤A损坏了线程1运行完AB步骤后的结果,等于把线程1所做的事破坏了.

解决方案 »

  1.   

    JAVA核心技术2第4版
    1.7.2节 同步访问共享资源
    张三的工资是共享资源。
    二楼说的,我不明白,我觉得我是对的,
      

  2.   

    Now, suppose the first thread executes Steps 1 and 2, and then it is
    interrupted. Suppose the second thread awakens and updates the same
    entry in the account array. Then, the first thread awakens and completes
    its Step 3.That action wipes out the modification of the other thread. As a result, the
    total is no longer correct.兄弟看的是中文版吧?建议你看英文版吧,呵呵.