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 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算