Hi!

This should be covered somewhere already but I can't find it. So here's my 
question:

Assume N workers running in a goroutine each and a number of Job tasks 
coming in.

The consensus appears to be to have one dispatcher goroutine collecting all 
jobs, then pulling a ready worker from a single queue of worker channels.
The workers put their individual queue (chan Job) into that single queue 
(chan chan Job) when they are ready to accept new work.

What I don't understand is why this is beneficial compared to the simpler 
approach of having all workers pull their work from one single chan Job 
like this:

func worker(q chan Job) {
  for {
    j <-q
   doWork(j)
  }
} 

func dispatch(q chan Job, j Job) {
  q<- j
}

(real world code would obviously select to also cover a quit signal channel)

So what am I missing? In both cases the workers will block when there's no 
work and the "dispatcher" uses whatever worker is available.


Best Regards,
Carsten

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to