[concurrency-interest] Fixed thread pool problem?

Joe Bowbeer joe.bowbeer at gmail.com
Fri Aug 31 14:58:36 EDT 2007


On 8/31/07, Glyn Normington <glyn.normington at gmail.com> wrote:
>
> [...] To highlight the undesirable behaviour,
> uncomment the line marked [A] and you'll find that all CPUs run at 100%. But
> if you comment out [A] again and uncomment the line marked [B], then only
> one processor is driven to 100% on average. I say on average because, on the
> systems I've tried, the hot thread seems to move between CPUs from time to
> time. It's a mystery to me why moving the infinite loop after the statement:
>

It's clear that uncommenting A causes all processors to run an infinite loop.

It's harder to explain why uncommenting B instead causes only one
processor to infinite loop.

Observe that uncommenting B will infinite loop whenever previous[i] is
not empty.  But note that the first step() invocation only adds a
generation to previous[1].  So only scanner #1 will infinite loop.

public void step() {
  Generation cur;
  int i;
  synchronized (this) {
    cur = current;
    prevIndex = ++prevIndex % PROCS;
    i = prevIndex;
  }
  synchronized (previous[i]) {
    ((ArrayList<Generation>) previous[i]).add(cur);
  }
  scheduleRepeatCheck();
}

--Joe


More information about the Concurrency-interest mailing list