Home | History | Annotate | Download | only in jm
      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.areturn.jm;
     18 
     19 import dxc.junit.opcodes.areturn.jm.T_areturn_7;
     20 
     21 public class T_areturn_7 implements Runnable {
     22     public final static int CNT = 1000;
     23     Integer value = new Integer(0);
     24     boolean failed = false;
     25 
     26     public void run() {
     27         for(int i = 0; i < CNT; i++) {
     28             test();
     29         }
     30     }
     31 
     32     private synchronized Integer test()  {
     33         Integer c = new Integer(value.intValue() + 1);
     34 
     35         value = c;
     36         Thread.yield();
     37         if(c != value)
     38             failed = true;
     39         return c;
     40     }
     41 
     42     public static boolean execute() {
     43         T_areturn_7 test = new T_areturn_7();
     44         Thread t1 = new Thread(test);
     45         Thread t2 = new Thread(test);
     46 
     47         t1.start();
     48         t2.start();
     49 
     50         try
     51         {
     52             Thread.sleep(5000);
     53         }
     54         catch(InterruptedException ie) {
     55             return false;
     56         }
     57 
     58         if(test.value.intValue() != CNT * 2)
     59             return false;
     60         return !test.failed;
     61     }
     62 }
     63