[concurrency-interest] Question about signalWork() implementation in the Fork Join Pool

Geert Denys gdenys at yahoo.com
Tue Jan 11 06:40:24 EST 2011


Could the Phaser be replaced by simply joining the subtask?

In that case, the main task can join the forked subtask and then do its post 
processing. Possibly, you avoid the problem with missed events.

- Geert


----- Original Message ----
From: Antoine CHAMBILLE <ach at quartetfs.com>
To: concurrency-interest at cs.oswego.edu
Sent: Tue, January 11, 2011 11:01:03 AM
Subject: [concurrency-interest] Question about signalWork() implementation in 
the Fork Join Pool

We are investigating dead lock issues in an application relying on the fork
join pool. We are using the latest (December 2010) jsr166y release.

We submit main tasks to the pool that process a number of items. Every n
item the task creates a subtask in charge of those n items, register the
subtask in a phaser, and forks the sub task. When the subtask completes it
arrives and deregisters from the phaser. Once all the groups of items have
been forked, the main task awaits the phaser, does a bit of post processing
and returns.

We continuously submit main tasks to the pool during the application life
and this works well for large periods of time (several hours) but regularly
at some point the pool deadlocks. Analysing the stack trace shows us that
most worker threads are blocked awaiting the phaser, and a few worker
threads are parked by awaitEvent() (untimed park), and never wake up while
only them could allow some progress. It looks like some of the fork events
have not been accounted for.


So we have this question about the implementation of signalWork() in the
fork join pool:
Why is compare and swap failure allowed when maintaining the event count of
the pool?

/**
     * Tries to advance eventCount and releases waiters. Called only
     * from workers.
     */
    final void signalWork() {
        int c; // try to increment event count -- CAS failure OK
        UNSAFE.compareAndSwapInt(this, eventCountOffset, c = eventCount,
c+1);
        if (eventWaiters != 0L)
            releaseEventWaiters();
    }


Antoine CHAMBILLE
QuartetFS

_______________________________________________
Concurrency-interest mailing list
Concurrency-interest at cs.oswego.edu
http://cs.oswego.edu/mailman/listinfo/concurrency-interest



      


More information about the Concurrency-interest mailing list