Skip to content

Commit

Permalink
Merge pull request #63 from singh264/openj9_issues_18089
Browse files Browse the repository at this point in the history
Adjust ThreadListStackTracesTest for checkReentrantLock
  • Loading branch information
babsingh authored Nov 17, 2023
2 parents 4b666c7 + aa716a1 commit 56e65df
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* ===========================================================================
* (c) Copyright IBM Corp. 2023, 2023 All Rights Reserved
* ===========================================================================
*/

/**
* @test
Expand All @@ -45,7 +50,15 @@ static void sleep(long millis) {
}

public void ensureReady(Thread vt, Thread.State expState) {
// wait while the thread is not ready or thread state is unexpected
/*
* Sleep for 1 second to allow the thread to reach the expected state.
* When the virtual thread is mounted, the virtual thread state,
* which is obtained from the carrier thread, can transition between
* WAITING and RUNNABLE before the virtual thread is parked on the
* lock.
*/
sleep(1000);
// Wait while the thread is not ready or thread state is unexpected.
while (!threadReady || (vt.getState() != expState)) {
sleep(1);
}
Expand Down Expand Up @@ -97,6 +110,10 @@ private static void checkReentrantLock() throws InterruptedException {
String name = "ReentrantLockTestTask";
TestTask task = new ReentrantLockTestTask();
Thread vt = Thread.ofVirtual().name(name).start(task);
// Wait until vt is waiting to acquire the lock.
while (!reentrantLock.hasQueuedThread(vt)) {
TestTask.sleep(1);
}
task.ensureReady(vt, expState);
checkStates(vt, expState);
}
Expand Down

0 comments on commit 56e65df

Please sign in to comment.