作者hikaru4 (光)
看板b96902HW
標題Re: [JAVA] 關於去年考古題的一些問題
時間Mon Jun 16 17:03:35 2008
※ 引述《hikaru4 (光)》之銘言:
: 關於thread的那題
: 4.Can it be guaranteed that, when the program stops, the value of counter is
: 0? Please explain your reason briefly (at most 3 lines). [4*(2+3)%]
: 去年網站上的答案是
: 4.
: (a) No. Main thread以及新產生的thread會交錯執行各自的for statement。
: (b) Yes. 因為執行的是run() 而不是start(),事實上第二個thread並沒有產生。
: (c) Yes. Main thread以及新產生的thread都鎖住同一Thread3 object。
: (d) No. Main thread鎖住Thread4 class,而新產生的thread鎖住Thread4 object。
喔喔 原來是誤會題目的意思了
題目應該是指 全部的 Thread 結束的時候
counter 的值
至於a為甚麼錯 應該是因為 counter++ counter--
其實在cpu中並不是單獨的一個步驟而已
所以有可能跟投影片吃蛋糕那個範例一樣 ++--的時候會出現錯誤
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.30.98