Skip to content

Commit

Permalink
8195057: java/util/concurrent/CountDownLatch/Basic.java failed w/ Xcomp
Browse files Browse the repository at this point in the history
Backport-of: 012c399
  • Loading branch information
GoeLin committed Feb 14, 2023
1 parent 7d7aa61 commit a220aaf
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions test/jdk/java/util/concurrent/CountDownLatch/Basic.java
Expand Up @@ -25,24 +25,27 @@
* @test
* @bug 6332435
* @summary Basic tests for CountDownLatch
* @library /test/lib
* @author Seetharam Avadhanam, Martin Buchholz
*/

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import jdk.test.lib.Utils;

interface AwaiterFactory {
Awaiter getAwaiter();
}
public class Basic {
static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);

abstract class Awaiter extends Thread {
private volatile Throwable result = null;
protected void result(Throwable result) { this.result = result; }
public Throwable result() { return this.result; }
}
interface AwaiterFactory {
Awaiter getAwaiter();
}

public class Basic {
abstract static class Awaiter extends Thread {
private volatile Throwable result = null;
protected void result(Throwable result) { this.result = result; }
public Throwable result() { return this.result; }
}

private void toTheStartingGate(CountDownLatch gate) {
try {
Expand Down Expand Up @@ -78,15 +81,12 @@ private Awaiter awaiter(final CountDownLatch latch,
catch (Throwable result) { result(result); }}};
}

private AwaiterFactory awaiterFactories(final CountDownLatch latch,
final CountDownLatch gate,
final int i) {
if (i == 1)
return new AwaiterFactory() { public Awaiter getAwaiter() {
return awaiter(latch, gate); }};
AwaiterFactory awaiterFactory(CountDownLatch latch, CountDownLatch gate) {
return () -> awaiter(latch, gate);
}

return new AwaiterFactory() { public Awaiter getAwaiter() {
return awaiter(latch, gate, 10000); }};
AwaiterFactory timedAwaiterFactory(CountDownLatch latch, CountDownLatch gate) {
return () -> awaiter(latch, gate, LONG_DELAY_MS);
}

//----------------------------------------------------------------
Expand All @@ -100,8 +100,8 @@ public static void normalUse() throws Throwable {

for (int i = 0; i < 3; i++) {
CountDownLatch gate = new CountDownLatch(4);
AwaiterFactory factory1 = test.awaiterFactories(latch, gate, 1);
AwaiterFactory factory2 = test.awaiterFactories(latch, gate, 0);
AwaiterFactory factory1 = test.awaiterFactory(latch, gate);
AwaiterFactory factory2 = test.timedAwaiterFactory(latch, gate);
a[count] = factory1.getAwaiter(); a[count++].start();
a[count] = factory1.getAwaiter(); a[count++].start();
a[count] = factory2.getAwaiter(); a[count++].start();
Expand Down Expand Up @@ -129,8 +129,8 @@ public static void threadInterrupted() throws Throwable {

for (int i = 0; i < 3; i++) {
CountDownLatch gate = new CountDownLatch(4);
AwaiterFactory factory1 = test.awaiterFactories(latch, gate, 1);
AwaiterFactory factory2 = test.awaiterFactories(latch, gate, 0);
AwaiterFactory factory1 = test.awaiterFactory(latch, gate);
AwaiterFactory factory2 = test.timedAwaiterFactory(latch, gate);
a[count] = factory1.getAwaiter(); a[count++].start();
a[count] = factory1.getAwaiter(); a[count++].start();
a[count] = factory2.getAwaiter(); a[count++].start();
Expand Down Expand Up @@ -162,8 +162,8 @@ public static void timeOut() throws Throwable {

for (int i = 0; i < 3; i++) {
CountDownLatch gate = new CountDownLatch(4);
AwaiterFactory factory1 = test.awaiterFactories(latch, gate, 1);
AwaiterFactory factory2 = test.awaiterFactories(latch, gate, 0);
AwaiterFactory factory1 = test.awaiterFactory(latch, gate);
AwaiterFactory factory2 = test.timedAwaiterFactory(latch, gate);
a[count] = test.awaiter(latch, gate, timeout[i]); a[count++].start();
a[count] = factory1.getAwaiter(); a[count++].start();
a[count] = factory2.getAwaiter(); a[count++].start();
Expand Down

1 comment on commit a220aaf

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.