23
23
24
24
package nsk .jvmti .GetCurrentContendedMonitor ;
25
25
26
- import nsk .share .Wicket ;
27
26
import java .io .PrintStream ;
28
27
29
28
public class contmon001 {
@@ -42,8 +41,8 @@ public class contmon001 {
42
41
}
43
42
}
44
43
45
- public static Wicket startingBarrier ;
46
- public static Wicket waitingBarrier ;
44
+ public static volatile boolean startingBarrier = true ;
45
+ public static volatile boolean waitingBarrier = true ;
47
46
static Object lockFld = new Object ();
48
47
49
48
static boolean DEBUG_MODE = false ;
@@ -55,6 +54,14 @@ public static void main(String[] args) {
55
54
System .exit (run (args , System .out ) + 95 /*STATUS_TEMP*/ );
56
55
}
57
56
57
+ public static void doSleep () {
58
+ try {
59
+ Thread .sleep (10 );
60
+ } catch (Exception e ) {
61
+ throw new Error ("Unexpected " + e );
62
+ }
63
+ }
64
+
58
65
public static int run (String argv [], PrintStream ref ) {
59
66
out = ref ;
60
67
for (int i = 0 ; i < argv .length ; i ++) {
@@ -75,13 +82,13 @@ public static int run(String argv[], PrintStream ref) {
75
82
out .println ("Check #1 done" );
76
83
77
84
contmon001a thr = new contmon001a ();
78
- startingBarrier = new Wicket ();
79
- waitingBarrier = new Wicket ();
80
85
81
86
thr .start ();
82
87
if (DEBUG_MODE )
83
88
out .println ("\n Waiting for auxiliary thread ..." );
84
- startingBarrier .waitFor ();
89
+ while (startingBarrier ) {
90
+ doSleep ();
91
+ }
85
92
if (DEBUG_MODE )
86
93
out .println ("Auxiliary thread is ready" );
87
94
@@ -93,7 +100,9 @@ public static int run(String argv[], PrintStream ref) {
93
100
94
101
thr .letItGo ();
95
102
96
- waitingBarrier .waitFor ();
103
+ while (waitingBarrier ) {
104
+ doSleep ();
105
+ }
97
106
synchronized (lockFld ) {
98
107
if (DEBUG_MODE )
99
108
out .println ("\n Main thread entered lockFld's monitor"
@@ -138,7 +147,7 @@ public void run() {
138
147
139
148
if (contmon001 .DEBUG_MODE )
140
149
contmon001 .out .println ("notifying main thread" );
141
- contmon001 .startingBarrier . unlock () ;
150
+ contmon001 .startingBarrier = false ;
142
151
143
152
if (contmon001 .DEBUG_MODE )
144
153
contmon001 .out .println ("thread is going to loop while <flag> is true ..." );
@@ -158,7 +167,7 @@ public void run() {
158
167
contmon001 .out .println ("looping is done: <flag> is false" );
159
168
160
169
synchronized (contmon001 .lockFld ) {
161
- contmon001 .waitingBarrier . unlock () ;
170
+ contmon001 .waitingBarrier = false ;
162
171
if (contmon001 .DEBUG_MODE )
163
172
contmon001 .out .println ("\n thread entered lockFld's monitor"
164
173
+ "\n \t and releasing it through the lockFld.wait() call" );
0 commit comments