1 Apr 2011 20:16
Possible deadlock in ForkJoinPool when parallelism = 1 ?
Aaron Dunlop <aaron.dunlop <at> gmail.com>
2011-04-01 18:16:49 GMT
2011-04-01 18:16:49 GMT
This is a follow-up to a similar posting at StackOverflow (http://stackoverflow.com/questions/5493399/forkjoinpool-parallelism-1-deadlock). I'm pretty new to the Fork-Join framework, so this is probably an obvious case of user-error, but I haven't been able to figure it out, and thus far, none of the comments on that post have resolved the issue either. I'm profiling a parallel algorithm over a range of thread-counts. My tasks seem to work flawlessly if I create the ForkJoinPool with parallelism > 1 (I've normally been running with 2-24 threads). But if I create the ForkJoinPool with parallelism = 1, I see deadlocks after an unpredictable number of iterations. And yes - setting parallelism = 1 is a strange practice, but I want to accurately ascertain the overhead of the parallel implementation, which means comparing the serial version and the parallel version run with a single thread. Below is a simple example that illustrates the issue I'm seeing. The 'task' is a dummy iteration over a fixed array, divided recursively into 16 subtasks. I chose this odd iteration simply to produce a memory-bound workload - it's possible the task itself interacts oddly with F-J or with JIT optimizations, but if so, I haven't been able to tease out those interactions. If run with THREADS = 2 (or more), it runs reliably to completion, but if run with THREADS = 1, it invariably deadlocks. After an unpredictable number of iterations, the main loop hangs in ForkJoinPool.invoke(), waiting in task.join(), and the worker thread exits. (I've been running between 10000 and 50000 ITERATIONS, depending on the host hardware)(Continue reading)
RSS Feed