Skip to content

Commit

Permalink
Fix Deadlock from Thread.suspend in Test (#39261) (#39341)
Browse files Browse the repository at this point in the history
* The lambda invoked by the `lockedExecutor` eventually gets JITed (which runs a static initializer that we will suspend in with a very tiny chance).
   * Fixed by creating the `Runnable` in the main test thread and using the same instance in all threads
* Closes #35686
  • Loading branch information
original-brownbear authored Feb 25, 2019
1 parent f17d408 commit 50d2736
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,18 @@ protected Pattern[] getUnsafeClasses() {
final LockedExecutor lockedExecutor = new LockedExecutor();
final AtomicLong ops = new AtomicLong();
final Thread[] threads = new Thread[5];
final Runnable yieldAndIncrement = () -> {
Thread.yield(); // give some chance to catch this stack trace
ops.incrementAndGet();
};
try {
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread(() -> {
for (int iter = 0; stop.get() == false; iter++) {
if (iter % 2 == 0) {
lockedExecutor.executeLocked(() -> {
Thread.yield(); // give some chance to catch this stack trace
ops.incrementAndGet();
});
lockedExecutor.executeLocked(yieldAndIncrement);
} else {
Thread.yield(); // give some chance to catch this stack trace
ops.incrementAndGet();
yieldAndIncrement.run();
}
}
});
Expand Down

0 comments on commit 50d2736

Please sign in to comment.