Reputation: 20470
I'm wondering as to whether channels are efficient enough to be used as part of coding a Go program.
Upvotes: 6
Views: 4626
Reputation: 24858
Channels in Go are not a function, they are a primitive type, a so called first-class citizen of the language.
In contrast to semaphores (aka. mutexes), channels are highly recommended since, when used correctly, they can serialize concurrent access very efficiently.
Go will certainly outperform any interpreted dynamic language and deals with concurrency way better than a lot of compiled languages. There are still a couple of use-cases where Go is not adequate, like in rocket controllers and the like but for normal real-world applications, Go is certainly one of the fastest and most flexible languages around.
Upvotes: 9
Reputation: 1170
Your question is odd, because obviously many Go programs do use channels efficiently so the answer is absolutely yes. But I think you may mean: Are channels efficient enough for my use case. If you can elaborate a bit more on what your program is supposed to do, then I can give you a better answer.
For what it's worth, I've used Go to write lots of highly performant programs that require lots and lots (from dozens to hundreds) of channels communicating across a similar number of goroutines. So yeah, they're pretty efficient in general.
Upvotes: 0
Reputation: 382454
Generally speaking, yes, channels are fast but we can't tell if you should use it without knowing your program. I'd say this part isn't constructive.
As for the implementation, it's available when you install Go with the sources. Look for exemple at src/pkg/runtime/chan.c
.
Most Go concurrent programs rely on channels. If you want to code in Go and execute concurrent tasks, I'd say you have almost no choice : use channels, profile, and see if you have a problem related to channels.
Upvotes: 5