FAQ
Hi,

I'm running into a deadlock issue when i'm trying to implement a worker
pattern using buffered channels & sync waitgroup as was advised in a
similar problem in an older post<https://groups.google.com/d/msg/golang-nuts/Kbh_QjIkU7M/oqu0tJHCryUJ>that i came across via search.

Here is the core Code on Go Playground <http://play.golang.org/p/6QZ0CA77lE> which
replicates the problem. I'm basically trying to start 3 worker goroutines
which will pull tasks from a buffered channel, do some time/disk intensive
operation (read from a file & take some actions on the content - simulating
here with sleep) and print the results.

This deadlocks but i'm not clear what i'm doing wrong.

Best Regards
Srinath

--
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/d/optout.

Search Discussions

  • Minux at Apr 21, 2014 at 6:40 pm

    On Mon, Apr 21, 2014 at 2:24 PM, Hariharan Srinath wrote:

    I'm running into a deadlock issue when i'm trying to implement a worker
    pattern using buffered channels & sync waitgroup as was advised in a
    similar problem in an older post<https://groups.google.com/d/msg/golang-nuts/Kbh_QjIkU7M/oqu0tJHCryUJ>that i came across via search.

    Here is the core Code on Go Playground<http://play.golang.org/p/6QZ0CA77lE> which
    replicates the problem. I'm basically trying to start 3 worker goroutines
    which will pull tasks from a buffered channel, do some time/disk intensive
    operation (read from a file & take some actions on the content - simulating
    here with sleep) and print the results.

    This deadlocks but i'm not clear what i'm doing wrong.
    the 2nd value from receive is not closed, i.e. if it's true, then the
    channel is NOT closed
    and the data is a valid data sent on the channel. (
    http://golang.org/ref/spec#Receive_operator)

    http://play.golang.org/p/CoPlxjUt2U

    --
    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/d/optout.
  • Hariharan Srinath at Apr 21, 2014 at 6:44 pm
    Oh ok got it! (forehead slap)

    Thanks a ton!

    Best regards
    Srinath

    --
    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/d/optout.
  • Dmitry Vyukov at Apr 22, 2014 at 3:48 am
    You usually do it with range:
    http://play.golang.org/p/Ww4haNsUmh


    On Mon, Apr 21, 2014 at 10:44 PM, Hariharan Srinath
    wrote:
    Oh ok got it! (forehead slap)

    Thanks a ton!

    Best regards
    Srinath

    --
    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/d/optout.
    --
    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/d/optout.
  • Hariharan Srinath at Apr 22, 2014 at 4:27 am
    Thanks! Using range looks a lot more elegant.

    Best regards
    Srinath

    --
    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/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedApr 21, '14 at 6:24p
activeApr 22, '14 at 4:27a
posts5
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase