News for hackers. Stuff that matters.
Re:Golang at CloudFlare by bad_user on Wednesday July 04, 2012 @01:55AM (#4197844)
I'm having a hard time understanding the benefits of goroutines compared to Actors on top of the JVM.

I never played with Go, but I was somehow under the impression that goroutines behave like processes and thus the only way to share data being through messages.

Re:Golang at CloudFlare by luriel on Wednesday July 04, 2012 @02:00AM (#4197854)
In one word: channels.

They might be theoretically equivalent to some degree, but in practice they are quite different, and I find reasoning about both concurrency and parallelism using goroutines and channels much more natural.

Also see this talk by Rob Pike on the origins of Go's concurrency model here: http://go-lang.cat-v.org/talks/

See also this article by Russ Cox about CSP: http://swtch.com/~rsc/thread/

And Rob Pike's latest talk about concurrency patterns at Google IO last week: http://www.youtube.com/watch?v=f6kdp27TYZs

Re:Golang at CloudFlare by eis on Wednesday July 04, 2012 @01:59AM (#4197852)
Have you used coroutines and threads before? Goroutines are basically coroutines multiplexed on threads. If you want to, you can even just think of them as super lightweight threads.

They are not like processes, they share the same address space.

Re:Golang at CloudFlare by luriel on Wednesday July 04, 2012 @02:06AM (#4197871)
> They are not like processes, they share the same address space.

Yes, but is worth remembering Go's (concurrency) motto:

Do not communicate by sharing memory; instead, share memory by communicating.

With channels you can send values, or pointers to the shared address space, so is much more efficient, or even channels (channels of channels are a very powerful and useful concept).

Re:Golang at CloudFlare by eis on Wednesday July 04, 2012 @02:20AM (#4197909)
Most of the time, following this principle will make sense. It should be also said though that it's not always the right choice.

There are situations where using locks or atomic instructions is the better choice. But they nearly only come up in performance critical contexts.

It would be very nice to have some kind of compile-time enforceable ownership of data regarding channels and goroutines because debugging thread-safety issues is a pita. I don't know how feasable it is to implement this though.

Re:Golang at CloudFlare by pcwalton on Wednesday July 04, 2012 @12:51PM (#4200047)
It is feasible if the language is carefully designed around it. Rust implements this through its uniqueness typing system. It is impossible to have two threads share mutable data.