FAQ
Rob Pike's example in slide
http://talks.golang.org/2012/concurrency.slide#38 mentions a round-trip
pattern where you block on a read to a channel you have just written into.
What are the rules associated with this pattern?

In particular I tried this out and I'm coming unstuck as the go routine
that reads from the channel, writes back into it, and then reads its own
value out of the channel in the next select body.

I'll try and distil a small example if it helps...

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Kamil Kisiel at Feb 27, 2013 at 5:01 pm
    Are you using a buffered channel? If you have an unbuffered channel as in
    the example then the send should block until another goroutine performs a
    receive.
    On Wednesday, February 27, 2013 8:55:08 AM UTC-8, matt wrote:

    Rob Pike's example in slide
    http://talks.golang.org/2012/concurrency.slide#38 mentions a round-trip
    pattern where you block on a read to a channel you have just written into.
    What are the rules associated with this pattern?

    In particular I tried this out and I'm coming unstuck as the go routine
    that reads from the channel, writes back into it, and then reads its own
    value out of the channel in the next select body.

    I'll try and distil a small example if it helps...
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Nate Finch at Feb 27, 2013 at 5:24 pm
    Writing to the channel will block until someone reads the value, unless the
    channel is buffered (rob was using unbuffered channels).

    See here: http://play.golang.org/p/wF3hsnH2uf

    the key part is this:

    // this send on the channel blocks until the worker goroutine reads from it
    quit <- "Say goodbye, Joe!"

    // the worker goroutine must have already read the quit you sent at this
    point
    // so now we're waiting for the quit message sent *from* the worker
    goroutine
    fmt.Println(<-quit)

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Matt at Feb 27, 2013 at 10:39 pm
    Thanks that's the bit I'd overlooked, its not buffered. Makes sense.

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedFeb 27, '13 at 4:55p
activeFeb 27, '13 at 10:39p
posts4
users3
websitegolang.org

3 users in discussion

Matt: 2 posts Kamil Kisiel: 1 post Nate Finch: 1 post

People

Translate

site design / logo © 2021 Grokbase