Example #1
0
 public static void main(String[] args) {
   ExecutorService exec = Executors.newCachedThreadPool();
   AtomicityTest at = new AtomicityTest();
   exec.execute(at);
   while (true) {
     int val = at.getValue();
     if (val % 2 != 0) {
       System.out.println(val);
       System.exit(0);
     }
   }
 }
Example #2
0
 public static void main(String[] args) {
   ExecutorService exec = Executors.newCachedThreadPool();
   AtomicityTest at = new AtomicityTest();
   exec.execute(at);
   while (true) {
     int val = at.getValue();
     // Prove that program will return non-even values and terminat;
     if (val % 2 != 0) {
       System.out.println(val);
       System.exit(0);
     }
   }
 }