Incase it helps, go version = go1.2.1 darwin/amd64
I have encountered an issue in unbuffered chans not synchronising even
though the chans have not been declared with any capacity. For some weird
reason, the receiving channels ends up reading duplicate values from the
channels.
Some work is being sent to be processed by a number of functions in a
pipeline that is determined at runtime. So each worker func has an input
and output chan similar to the pipelines description
here: http://blog.golang.org/pipelines
So it starts with the declaration
out := make(chan work)
go func() {
for _, record := range ac.rc.RL {
out <- work{ac.rc.Headers, &record}
}
close(out)
}()
then for each func create to process data in the pipeline
var nxt <-chan work = out
for _, w := range ac.rw {
nxt = w.Work(nxt)
}
Each Work func declares a chan, reads from the input chan it receives in a
separate go routine and returns "out"
out := make(chan work)
go func() {
for j := range in {
// does something and sends result to out
out <- result
}
close(out)
}()
return out
The problem is that multiple values are sent before the Work function reads
one and when that happens, it reads the same duplicate value. I'm guessing
I am doing something wrong and probably missing something obvious. When I
put a delay as tiny as 1ms (obviously not good practise), all is well.
Thanks in advance if anything is spotted that I've missed
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.