[dl.u.c] PooledExecutor race ?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[dl.u.c] PooledExecutor race ?

Ernst, Matthias
Hi,

I have a vague memory of this being discussed before, but anyways:

I have a thread dump from a customer with a e.o.cs.dl.u.c.PooledExecutor
that has a thread in WaitWhenBlocked, waiting on the synchronous channel
(Pool was created using new PooledExecutor(maxSize);
pool.waitWhenBlocked).

Yet I cannot see any active worker thread that would eventually take
over the offered work.

When looking at this, I think I found a race condition between the last
part of #execute after the synchronized block and workerDone().

Assume a pool with maxSize=1, the only worker busy.

T1 in #execute: leaves the synchronized block heading for the
blockedExecutionHandler.
T2 in Worker#run: for example, task.run throws, executes workerDone,
decrements pool size to 0, polls the handOff --- nothing there yet, so
it quits.
T1 reaches WaitWhenBlocked and waits forever.


A simple testcase hangs shortly after start:

package test;

import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;

public class PooledExecutorTest {
  public static void main(String[] args) throws InterruptedException {
    PooledExecutor pool = new PooledExecutor(1);
    pool.waitWhenBlocked();

    while(true) {
      pool.execute(new Runnable() {
          public void run() {
            throw new RuntimeException();
          }
      });
    }
  }
}

With maximum pool size=2 the test lives longer but still comes to halt
eventually.

Matthias

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest