douzhengyi5022 2009-11-13 17:14
浏览 98

共享内存与Go通道通信

One of Go's slogans is Do not communicate by sharing memory; instead, share memory by communicating.

I am wondering whether Go allows two different Go-compiled binaries running on the same machine to communicate with one another (i.e. client-server), and how fast that would be in comparison to boost::interprocess in C++? All the examples I've seen so far only illustrate communication between same-program routines.

A simple Go example (with separate client and sever code) would be much appreciated!

  • 写回答

3条回答 默认 最新

  • dongsong1911 2009-11-13 17:27
    关注

    One of the first things I thought of when I read this was Stackless Python. The channels in Go remind me a lot of Stackless Python, but that's likely because (a) I've used it and (b) the language/thoughts that they actually came from I've never touched.

    I've never attempted to use channels as IPC, but that's probably because the alternative is likely much safer. Here's some psuedocode:

    program1

    chan = channel()
    ipc = IPCManager(chan, None)
    send_to_other_app(ipc.underlying_method)
    
    chan.send("Ahoy!")
    

    program2

    chan = channel()
    recv_from_other_app(underlying_method)
    ipc = IPCManager(chan, underlying_method)
    
    ahoy = chan.recv()
    

    If you use a traditional IPC method, you can have channels at each side that wrap their communication on top of it. This leads to some issues in implementation, which I can't even think about how to tackle, and likely a few unexpected race conditions.

    However, I agree; the ability to communicate via processes using the same flexibility of Go channels would be phenomenal (but I fear unstable).

    Wrapping a simple socket with channels on each side gets you almost all of the benefits, however.

    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记