aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Dumb question about threads Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Dumb question about threads" Watch "Dumb question about threads" New topic
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dumb question about threads
 
Similar Threads
One more on threads
Synchronization Methods
Thread Question
synchronized methods + Threads
Mughal rasmussen question