1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package dxc.junit.opcodes.invokestatic.jm; 18 19 public class T_invokestatic_12 implements Runnable { 20 public final static int CNT = 1000; 21 static int value = 0; 22 static boolean failed = false; 23 24 public void run() { 25 for(int i = 0; i < CNT; i++) { 26 test(); 27 } 28 } 29 30 private synchronized static void test() { 31 value++; 32 int c = value; 33 Thread.yield(); 34 if(c != value) 35 failed = true; 36 } 37 38 public static boolean execute() { 39 T_invokestatic_12 test = new T_invokestatic_12(); 40 Thread t1 = new Thread(test); 41 Thread t2 = new Thread(test); 42 43 t1.start(); 44 t2.start(); 45 46 try 47 { 48 Thread.sleep(5000); 49 } 50 catch(InterruptedException ie) { 51 return false; 52 } 53 54 if(value != CNT * 2) 55 return false; 56 return !failed; 57 } 58 }