[concurrency-interest] leaders/followers pattern

David Holmes dholmes at dltech.com.au
Tue Jun 7 21:13:06 EDT 2005


Mohan,

>      I am looking for some ideas about the comparison between the
> leaders/followers pattern and the Worker thread pattern. In our
> framework a
> Worker thread picks up tasks and assigns them to a thread from a
> pool. I read that this pattern reduces context switching.

I'm not clear on what the "leaders/followers" pattern actually is. But from
your description instead of having multiple workers pull from a work queue,
you instead have a single worker that pulls from the queue and then
hands-off to a thread from a "pool".

>From an abstract perspective, assuming sufficient CPU's to handle all
incoming tasks, then the design you describe has more context switches due
to the hand off from the single worker to the pool thread - you can cut out
the "middle man". That single worker can also become the bottleneck.

A decent pool will only wake up at most one thread in the pool for each item
of work that arrives - but a badly written pool might do a notifyAll and
wake them all up. So perhaps what you read was reflecting experience with a
concrete implementation, rather than an abstract analysis of the pattern
itself.

Cheers,
David Holmes





More information about the Concurrency-interest mailing list