On Wednesday, September 26, 2012 4:30:17 AM UTC-4,
xavier...@gmail.com wrote:
Go implements coroutines for communicating between two threads. Dart implements this need by isolates... But Isolates are also able to perform communication between two processes according to the VM implementation choice.
What if Go would implements a method to perform this communication through theads or processus via an unified channel? Netchannels could be used but it is to heavy for communication on the same machine.
What is the idiomatic way to do this in Go?
I can't speak for anyone else, but I "stalled" on a couple parts of this question.
- I'm not sure what you mean by "Go implements coroutines for communicating between two threads." I would say, Go has something similar to coroutines called goroutines, which the runtime can automatically switch between threads, and which normally communicate with each other using channels, basically a threadsafe FIFO, though they can also use shared memory more directly.
- I don't know Dart, and don't know what an Isolate is, or what a netchannel is.
Your question appears to be:
Dart uses the same mechanism to communicate between threads in the same process, and between different processes. What's the best way to do that in Go?
Do I have that more-or-less right?
If so, I'd hazard a guess that a good way (dunno about the best way) is through net/rpc using JSON or gobs. I bet with just a little work you could wrap a channel around that. (Or maybe net/rpc does that already, I haven't played with it.)
But ... would you really want to? It seems to me that there are a lot more things that can go wrong with networked RPC than with a regular channel between two threads. Trying to use the same abstraction around two very different transport mechanisms seems fraught with peril. (I think I read an essay by someone at Microsoft about this when they made networked file systems look like local file systems. Suddenly a simple file copy was actually a network transfer, with all the issues of dns, network timeouts, and so on that came with it, but the "file copy" code wasn't really built to handle any of that. This is what makes me think that channels-over-RPC might be a bad idea.)
But I might just not understand your question, and could certainly be wrong, regardless. :) But I thought I'd take a stab at it.
-- Larry