共享内存与消息传递 Shared memory versus message passing

来源:互联网 发布:mac自动同步iphone照片 编辑:程序博客网 时间:2024/05/21 17:22

Shared memory versus message passing

Tasks can use two different methods to communicate with each other. The first one is shared memory, and normally it is used when the tasks are running in the same computer. The tasks use the same memory area where they write and read values. To avoid problems, the access to this shared memory has to be in a critical section protected by a synchronization mechanism.
The other synchronization mechanism is message passing and normally is used when the tasks are running in different computers. When a task needs to communicate with another, it sends a message that follows a predefined protocol. This communication can be synchronous if the sender is blocked waiting for a response or asynchronous if the sender continues with their execution after sending the message.


任务可以使用两种不同的方法进行通信。 第一是共享内存,通常当任务在同一台计算机上运行时使用。 任务使用相同的内存区域来写入和读取值。 为了避免问题,对共享内存的访问必须位于受同步机制保护的关键部分。
另一种同步机制是消息传递,当任务在不同的计算机上运行时通常使用。 当任务需要与另一个进行通信时,它会发送遵循预定义协议的消息。 如果发送方在发送消息后继续执行,发送方被阻塞等待响应或异步,则该通信可以是同步的。