2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package gov.nasa.jpf.test.mc.threads;
21 import gov.nasa.jpf.util.test.TestJPF;
23 import org.junit.Test;
26 * high order data race
28 public class HORaceTest extends TestJPF {
41 Thread.yield(); // give the 2nd thread a chance to interfere
45 synchronized int getA() { return a; }
46 synchronized int getB() { return b; }
47 synchronized void setA(int x){ a = x; }
48 synchronized void setB(int x){ b = x; }
50 synchronized void change(int delta) {
55 synchronized boolean isConsistent() {
64 public void testHighOrderRace() {
66 if (verifyAssertionErrorDetails("inconsistent d2")) {
69 Thread t1 = new Thread() {
76 Thread t2 = new Thread() {
90 } catch (InterruptedException ix) {
91 fail("unexpected interrupt during {t1,t2}.join()");
94 System.out.print("d2 = ");
95 System.out.print(d2.a);
96 System.out.print(',');
97 System.out.println(d2.b);
99 assert d2.isConsistent() : "inconsistent d2";