01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.harmony.drlvm.tests.regression.h5206;
19:
20: import junit.framework.TestCase;
21:
22: public class VolatileLongTest extends TestCase {
23: private class Interrupter extends Thread {
24: Thread int_th;
25: long timeout;
26:
27: Interrupter(Thread int_th, long timeout) {
28: this .int_th = int_th;
29: this .timeout = timeout;
30: }
31:
32: public void run() {
33: try {
34: Thread.sleep(timeout);
35: } catch (Throwable ex) {
36: }
37: int_th.interrupt();
38: }
39: }
40:
41: long lo;
42: long hi;
43: volatile long v;
44:
45: public static void main(String[] args) {
46: new VolatileLongTest().test();
47: }
48:
49: public void test() {
50: lo = 0x00000000FFFFFFFFL;
51: hi = 0xFFFFFFFF00000000L;
52: v = hi;
53:
54: Thread t1 = new Thread() {
55: public void run() {
56: while (!isInterrupted()) {
57: v = lo;
58: v = hi;
59: }
60: }
61: };
62: Thread t2 = new Thread() {
63: public void run() {
64: while (!isInterrupted()) {
65: v = hi;
66: v = lo;
67: }
68: }
69: };
70:
71: boolean passed = true;
72: long v_copy = 0;
73:
74: t1.start();
75: t2.start();
76: new Interrupter(Thread.currentThread(), 10000).start();
77:
78: while (!Thread.currentThread().interrupted()) {
79: Thread.yield();
80: v_copy = v;
81: if (v_copy != lo && v_copy != hi) {
82: passed = false;
83: break;
84: }
85: }
86:
87: t1.interrupt();
88: t2.interrupt();
89:
90: assertTrue("" + v_copy, passed);
91:
92: System.out.println("PASSED");
93: }
94: }
|