同步与互斥的理解

Mutual exclusion 

means that only a single thread should be able to access the shared resource at any given point of time. This avoids the race conditions between threads acquireing the resource. Monitors and Locks provide the functionality to do so.

Synchronization

means that you synchronize/order the access of multiple threads to the shared resource.
Consider the example:
If you have two threads, Thread 1 & Thread 2.
Thread 1 and Thread 2 execute in parallel but before Thread 1 can execute say a statement A in its sequence it is a must that Thread 2 should execute a statement B in its sequence. What you need here is synchronization. A semaphore provides that. You put a semapohore wait before the statement A in Thread 1 and you post to the semaphore after statement B in Thread 2.
This ensures the synchronization you need.

摘抄自: https://stackoverflow.com/questions/10100923/difference-between-mutual-exclusion-and-synchronization

 

在多道程序设计系统中,同一时刻可能有许多进程,这些进程之间存在两种基本关系:竞争关系和协作关系。

进程的互斥、同步、通信都是基于这两种基本关系而存在的,为了解决进程间竞争关系(间接制约关系)而引入进程互斥;为了解决进程间松散的协作关系(直接制约关系)而引入进程同步;为了解决进程间紧密的协作关系而引入进程通信

摘抄自:https://www.jianshu.com/p/6ffecb5a1333

 
 
posted @ 2019-07-02 17:13  ba哥  阅读(757)  评论(0编辑  收藏  举报