Skip to content

Commit

Permalink
use VThreadPinner
Browse files Browse the repository at this point in the history
  • Loading branch information
pchilano committed Jul 8, 2024
1 parent 0490e6c commit ce77759
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions test/jdk/java/lang/Thread/virtual/ThreadYield.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @bug 8335269
* @summary Test that Thread.yield loop polls for safepoints
* @requires vm.continuations
* @modules java.base/java.lang:+open
* @library /test/lib
* @run junit/othervm ThreadYield
*/

Expand All @@ -35,36 +35,39 @@
* @bug 8335269
* @summary Test that Thread.yield loop polls for safepoints
* @requires vm.continuations
* @modules java.base/java.lang:+open
* @library /test/lib
* @run junit/othervm -Xcomp -XX:-TieredCompilation -XX:CompileCommand=inline,*::yield* -XX:CompileCommand=inline,*::*Yield ThreadYield
*/

import java.util.concurrent.atomic.AtomicBoolean;

import jdk.test.lib.thread.VThreadPinner;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

class ThreadYield {
static void foo(AtomicBoolean done) {
synchronized (done) {
while (!done.get()) {
Thread.yield();
}
while (!done.get()) {
Thread.yield();
}
}

@Test
void testThreadYieldPolls() throws Exception {
AtomicBoolean done = new AtomicBoolean();
var vthread = Thread.ofVirtual().start(() -> foo(done));
var vthread = Thread.ofVirtual().start(() -> {
VThreadPinner.runPinned(() -> foo(done));
});
Thread.sleep(5000);
done.set(true);
vthread.join();

System.out.println("First vthread done");

AtomicBoolean done2 = new AtomicBoolean();
vthread = Thread.ofVirtual().start(() -> foo(done2));
vthread = Thread.ofVirtual().start(() -> {
VThreadPinner.runPinned(() -> foo(done2));
});
long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < 5000) {
Thread.sleep(250);
Expand Down

0 comments on commit ce77759

Please sign in to comment.