wood burning stoves 2.0*
The moose likes Threads and Synchronization and the fly likes synchronization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "synchronization" Watch "synchronization" New topic
Author

synchronization

Eric Lidell
Greenhorn

Joined: Jul 02, 2003
Posts: 20
Look at the following question i picked up in the internet.
public class Vertical {
private int alt;
public synchronized void up() {
++alt;
}
public void down() {
--alt;
}
public synchronized void jump() {
int a = alt;
up();
down();
assert(a == alt);
}
}
if the code is run with assertions enabled ,what are the possible answers?
a.The code will fail to compile.
b.Seperate threads can execute up() concurrently
c.Seperate threads can execute down() concurrently
d.Seperate threads can execute both up() & down() concurrently
e.the assertion wont fail under any circumstance.
What is the possible answer and the reason?
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
Simon Templar,
We don't have many rules at JavaRanch, but one that we do have is a naming convention. If you would be a saint and kindly change your display name to conform, it would be most appreciated.
Thanks,
Jason (moderator)
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
I'm moving this to The Threads and Synchronization Forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: synchronization