Ornamental Garden - Counter Class
Ornamental Garden - Counter Class
class Counter {
int value_=0;
public void increment() {
int temp = value_; //read
Simulate.interrupt();
++temp; //add1
value_=temp; //write
}
}
The simulated interrupt simply calls yield() randomly to force a thread switch.
This is to make sure the demonstration works on all Java virtual machines.