Skip to content

Commit

Permalink
[Wisp] Fix PassTokenTest
Browse files Browse the repository at this point in the history
Summary: There is an unlocked time window between pass token and notify
next, causing the test to occasionally fail.

Test Plan: PassTokenTest

Reviewed-by: D-D-H, joeylee97

Issue: dragonwell-project/dragonwell8#290
  • Loading branch information
yuleil committed Jan 27, 2022
1 parent 0bd1f67 commit c2f47b9
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions test/com/alibaba/wisp/monitor/PassTokenTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.concurrent.locks.ReentrantLock;

import static jdk.testlibrary.Asserts.assertTrue;
import static jdk.testlibrary.Asserts.fail;

public class PassTokenTest {
private final static boolean needCheckStealEnable = Boolean.getBoolean("checkStealEnable");
Expand Down Expand Up @@ -133,11 +134,13 @@ public void run() {
cond.await();
checkStealEnable(task);
} catch (InterruptedException e) {
e.printStackTrace();
fail(e.getMessage());
}
}
if (++current % 10000 == 0) // pass the token
if (++current % 10000 == 0) {// pass the token
System.out.println(SharedSecrets.getJavaLangAccess().currentThread0().getName() + "\t" + current);
}
cond.signalAll();
} finally {
lock.unlock();
}
Expand All @@ -148,23 +151,12 @@ public void run() {
lock.wait();
checkStealEnable(task);
} catch (InterruptedException e) {
e.printStackTrace();
fail(e.getMessage());
}
}
if (++current % 10000 == 0) // pass the token
if (++current % 10000 == 0) {// pass the token
System.out.println(SharedSecrets.getJavaLangAccess().currentThread0().getName() + "\t" + current);
}
}

if (JUC) {
lock.lock();
try {
cond.signalAll();
} finally {
lock.unlock();
}
} else {
synchronized (lock) {
}
lock.notifyAll();
}
}
Expand Down

0 comments on commit c2f47b9

Please sign in to comment.