Hi Gophers; theory question here!
Using goroutines and channels is concurrecy under the CSP model. If I where to use a buffered channel however, would this make it fit under the banner of the actor model?
Bonus questions: I like using the actor model (mainly with Java/Akka) and the CSP model (with Go). Akka allows actors to easily message each other over a network, making horizontal distribution easy. Go standard libs doesn't seem to support messages over network, is this something that will be added or are there any good 3rd party libs for this?
Thanks for reading
TD;LR: do GoRoutines with buffered channels conform to the actor model rather than CSP?
评论:
Ainar-G:
roveboat:I can kinda answer your bonus question. There was a netchan package for emulating buffered channels over the network, but it's deprecated for some reason. There is also std's net/rpc package that can be used for inter-machine communication.
As for your main question, I don't know enough about actor model, so I can't really answer that.
tcolgate:There's libchan these days. With a quick glimpse, buffering would need to be implemented manually.
CzarSkye:Without some further framework actually enforcing the axioms of the actor model then no. With such a framework, then, well yes (though it's not obvious that buffering really has anything to do with it). Even on a simpler level you don't have a built in notion of being able to identify who sent something to you (I think that's part of the actor model, you know who sent you something).
Personally, I'd say it makes more sense to focus on the idomatic use of the language, which is (fairly obviously) closer to CSP, anyway. And don't be too eager to use buffered channels.
I believe netchan was removed from before 1.0 as it wasn't felt sufficiently complete, though there is a strong desire to put it back. grpc with streams and contexts might provide a better toolset to build on that the inbuilt rpc package, but you still aren't going to get channel semantics without a lot of effort.
yes, I think you might be right there, I overlooked sender identification within a message, which is present (and necessary) in the akka framework I use.
99% of the time the CSP model works great for me, I love that channel messages offers simple synchronization of go routines. I don't think it would be too hard at all to implement the actor model in go though, I may have a go as an interesting side project, and for some use cases it is just easier to use.
