@@ -109,18 +109,24 @@ public void stress() throws InterruptedException {
109
109
Thread [] vThreads = IntStream .range (0 , 1024 ).mapToObj (_ ->
110
110
Thread .ofVirtual ().start (() -> {
111
111
long threadId = Thread .currentThread ().threadId ();
112
- while (true ) {
113
- try (Arena arena = stack .pushFrame (JAVA_LONG .byteSize (), JAVA_LONG .byteAlignment ())) {
114
- // Try to assert no two vThreads get allocated the same stack space.
115
- MemorySegment segment = arena .allocate (JAVA_LONG );
116
- JAVA_LONG .varHandle ().setVolatile (segment , 0L , threadId );
117
- Assert .assertEquals (threadId , (long ) JAVA_LONG .varHandle ().getVolatile (segment , 0L ));
112
+ while (!Thread .interrupted ()) {
113
+ for (int i = 0 ; i < 1_000_000 ; i ++) {
114
+ try (Arena arena = stack .pushFrame (JAVA_LONG .byteSize (), JAVA_LONG .byteAlignment ())) {
115
+ // Try to assert no two vThreads get allocated the same stack space.
116
+ MemorySegment segment = arena .allocate (JAVA_LONG );
117
+ JAVA_LONG .varHandle ().setVolatile (segment , 0L , threadId );
118
+ Assert .assertEquals (threadId , (long ) JAVA_LONG .varHandle ().getVolatile (segment , 0L ));
119
+ }
118
120
}
121
+ Thread .yield (); // make sure the driver thread gets a chance.
119
122
}
120
123
})).toArray (Thread []::new );
121
124
Thread .sleep (Duration .of (10 , SECONDS ));
122
125
Arrays .stream (vThreads ).forEach (
123
- thread -> Assert .assertTrue (thread .isAlive ()));
126
+ thread -> {
127
+ Assert .assertTrue (thread .isAlive ());
128
+ thread .interrupt ();
129
+ });
124
130
}
125
131
126
132
static {
0 commit comments