What to use instead of the “lock” statement when the code is running on multiple machines?

后端 未结 5 2116
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-13 10:02

The lock statement ensures that one thread does not enter a critical section of code while another thread is in the critical section. However, it won\'t work if the workload is

5条回答
  •  粉色の甜心
    2021-02-13 10:41

    Since a network of machines in a standard scenario does not operate on shared memory, they have no global view of a single variable that can be used for synchronization. Therefore, you have to implement locks by means of message passing.

    If you want to lock shared resources, you can have a central "master" regulate access to that resource.

    Edit: If what you need is not sharing resources (e.g. a barrier), you can use for example MSMQ to pass messages between the machines. Probably sockets are too low level.

提交回复
热议问题