jdk/test/java/util/concurrent/ConcurrentQueues/RemovePollRace.java
changeset 35981 e3e89c0bb3d9
parent 32991 b27c76b82713
child 43522 f9c6f543c4db
equal deleted inserted replaced
35980:1fc60a70d779 35981:e3e89c0bb3d9
   119     void test(final Queue<Boolean> q) throws Throwable {
   119     void test(final Queue<Boolean> q) throws Throwable {
   120         long t0 = System.nanoTime();
   120         long t0 = System.nanoTime();
   121         final int SPINS = 5;
   121         final int SPINS = 5;
   122         final AtomicLong removes = new AtomicLong(0);
   122         final AtomicLong removes = new AtomicLong(0);
   123         final AtomicLong polls = new AtomicLong(0);
   123         final AtomicLong polls = new AtomicLong(0);
   124         final int adderCount =
   124 
   125             Math.max(1, Runtime.getRuntime().availableProcessors() / 4);
   125         // We need at least 3 threads, but we don't want to use too
   126         final int removerCount =
   126         // many on massively multi-core systems.
   127             Math.max(1, Runtime.getRuntime().availableProcessors() / 4);
   127         final int cpus = Runtime.getRuntime().availableProcessors();
       
   128         final int threadsToUse = Math.max(3, Math.min(cpus, 16));
       
   129         final int adderCount = threadsToUse / 3;
       
   130         final int removerCount = adderCount;
   128         final int pollerCount = removerCount;
   131         final int pollerCount = removerCount;
   129         final int threadCount = adderCount + removerCount + pollerCount;
   132         final int threadCount = adderCount + removerCount + pollerCount;
       
   133 
   130         final CountDownLatch startingGate = new CountDownLatch(1);
   134         final CountDownLatch startingGate = new CountDownLatch(1);
   131         final CountDownLatch addersDone = new CountDownLatch(adderCount);
   135         final CountDownLatch addersDone = new CountDownLatch(adderCount);
   132         final Runnable remover = new Runnable() {
   136         final Runnable remover = new Runnable() {
   133             public void run() {
   137             public void run() {
   134                 await(startingGate);
   138                 await(startingGate);