| Author |
Dumb question about threads
|
Max Bazhenov
Greenhorn
Joined: Oct 30, 2004
Posts: 18
|
|
Given the following code, which statements concerning the objects referenced through the member variables i, j and k are true, given that any thread may call the methods a(), b() and c() at any time? A. i.v is guaranteed always to be 0 or 1. B. j.v is guaranteed always to be 0 or 1. C. k.v is guaranteed always to be 0 or 1. D. j.v will always be greater than or equal to k.v at any give time. E. k.v will always be greater than or equal to j.v at any give time. ANSWERS: A, B Why A is correct? Assume that one thread executes method's a() i.inc(), after that another thread executes method's b() i.inc(). Value of i.v will be 2, isn't it ? Where am I mistaken ?  [ November 12, 2004: Message edited by: Barry Gaunt ]
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
|
Result of searching for same question
|
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
|
 |
 |
|
|
subject: Dumb question about threads
|
|
|