I have a talk in Singapore a few months ago trying to explore this idea. It sort of went in a different direction, but the conclusion might be interesting for you.
// ... s.mtx.Lock() // ... s.ch <- val // might block! s.mtx.Unlock() // ...
I stumbled over a nice and very interesting Blog entry "Go channels are bad and you should feel bad" , I would like to hear some opinions about that articlefrom seasoned go developers. Because I just used go for a couple of months for my private web projects and rarely get in touch with channels.
.... The microsecond or so of cost you see I understood was *not* due to there being thousands of operations needed to run the channel, but the latency added by the stall, and scheduler overhead.
--
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.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
No. Use channels to coordinate and send data between goroutines, and other sync primitives to coordinate access to shared resources. Both has its pros and cons, use the best tool for the job.
--
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.
I think that both of the suggestions below are great. But I’m left wondering about the Go mantra
Do not communicate by sharing memory. Instead, share memory by communicating.
What does it say? It starts off with communicating as the goal, but doesn’t tell you how to do it. Then sharing memory is the goal and the solution it provides (communicating) is only right some of the time.
Am I missing something? Should this be replaced?
John
John Souvestre - New Orleans LA
From: golan...@googlegroups.com [mailto:golan...@googlegroups.com] On Behalf Of Michael Jones
Sent: 2017 August 18, Fri 08:57
To: Tamás Gulácsi
Cc: golang-nuts
Subject: Re: [go-nuts] Go channels overused and hyped?
yes... everything is good for what it is designed for and less-good for what it is not designed for.
mutex-protected counters are good
channels for data communication are good
neither is a perfect stand in for the other. nothin wrong with channels.
On Fri, Aug 18, 2017 at 4:38 AM, Tamás Gulácsi <tgula...@gmail.com> wrote:
No. Use channels to coordinate and send data between goroutines, and other sync primitives to coordinate access to shared resources. Both has its pros and cons, use the best tool for the job.
--
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...@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...@googlegroups.com.
P.S.
And if you want to reduce it to a one-liner, how about this?
Communicating is better than sharing sometimes, and vice versa.
John
John Souvestre - New Orleans LA
From: John Souvestre [mailto:Jo...@Souvestre.com]
Sent: 2017 August 18, Fri 14:03
To: 'golang-nuts'
Subject: RE: [go-nuts] Go channels overused and hyped?
I think that both of the suggestions below are great. But I’m left wondering about the Go mantra
Do not communicate by sharing memory. Instead, share memory by communicating.
What does it say? It starts off with communicating as the goal, but doesn’t tell you how to do it. Then sharing memory is the goal and the solution it provides (communicating) is only right some of the time.
Am I missing something? Should this be replaced?
John
John Souvestre - New Orleans LA
From: golan...@googlegroups.com [mailto:golan...@googlegroups.com] On Behalf Of Michael Jones
Sent: 2017 August 18, Fri 08:57
To: Tamás Gulácsi
Cc: golang-nuts
Subject: Re: [go-nuts] Go channels overused and hyped?
yes... everything is good for what it is designed for and less-good for what it is not designed for.
mutex-protected counters are good
channels for data communication are good
neither is a perfect stand in for the other. nothin wrong with channels.
On Fri, Aug 18, 2017 at 4:38 AM, Tamás Gulácsi <tgula...@gmail.com> wrote:
No. Use channels to coordinate and send data between goroutines, and other sync primitives to coordinate access to shared resources. Both has its pros and cons, use the best tool for the job.
--
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...@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...@googlegroups.com.
Mutexes are good for a some low level tasks, and when you must have a shared data structure with no clear owner. When in doubt, and when designing your app, prefer communication over sharing, i.e. channels.