Modern operating systems are mostly multitasking operating systems, with a large number of scheduled entities running at the same time. In a multitasking operating system, multiple tasks that run concurrently may:
- All require access/use of the same resource
- There is a dependency between multiple tasks, and a task's run depends on another task
These two situations are the most basic problems encountered in multi-task programming, and also the core problem in multi-task programming, and synchronization and mutual exclusion are the two problems to solve.
Mutual exclusion : refers to the number of pieces of a walk between different tasks, when a task runs one of the program fragments, other tasks can not run any of their program fragments, only wait until the task runs out of this program fragment to run. The basic scenario is that a common resource can only be used by one process or thread at a time, and multiple processes or threads cannot use common resources at the same time.
synchronization : Refers to a number of pieces of a walk between different tasks, their operation must be in strict accordance with the specified sequence of operations, which depends on the specific task to be completed. The most basic scenario is that two or more two or more processes or threads work together in a predetermined sequence of steps. A task, for example, relies on the data generated by the B task.
Obviously, synchronization is a more complex mutex, and mutual exclusion is a special kind of synchronization . That is, mutual exclusion is that two tasks can not run at the same time, they will repel each other, must wait for one thread to run, another to run, and synchronization can not run concurrently, but he must be in some order to run the corresponding thread (also a mutex)! Therefore, mutexes are unique and exclusive, but mutual exclusion does not limit the order in which tasks are run, that is, tasks are unordered, and there is a sequential relationship between tasks that are synchronized.
Transferred from: http://blog.csdn.net/tennysonsky/article/details/46273709
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Multi-tasking synchronization and mutual exclusion