|
In computer science, synchronization refers to one of two distinct but related concepts: synchronization of processes, and synchronization of data. ''Process synchronization'' refers to the idea that multiple processes are to join up or handshake at a certain point, in order to reach an agreement or commit to a certain sequence of action. ''Data synchronization'' refers to the idea of keeping multiple copies of a dataset in coherence with one another, or to maintain data integrity. Process synchronization primitives are commonly used to implement data synchronization. ==Thread or process synchronization== Thread synchronization is defined as a mechanism which ensures that two or more concurrent processes or threads do not simultaneously execute some particular program segment known as mutual exclusion. When one thread starts executing the critical section (serialized segment of the program) the other thread should wait until the first thread finishes. If proper synchronization techniques〔 〕 are not applied, it may cause a race condition where, the values of variables may be unpredictable and vary depending on the timings of context switches of the processes or threads. For example, suppose that there are three processes namely, 1, 2 and 3. All three of them are concurrently executing and then need to share a common resource (critical section) as shown in Figure 1. Synchronization should be used here to avoid any conflicts for accessing this shared resource. Hence, when Process 1 and 2 both try to access that resource it should be assigned to only one process at a time. If it is assigned to Process 1, the other process (Process 2) needs to wait until Process 1 frees that resource (as shown in Figure 2). Another synchronization requirement which needs to be considered is the order in which particular processes or threads should be executed. For example, we cannot board a plane until we buy the required ticket. Similarly, we cannot check emails before validating our credentials (i.e., user name and password). In the same way, an ATM will not provide any service until we provide it with a correct PIN. Other than mutual exclusion, synchronization also deals with the following: * deadlock, which occurs when many processes are waiting for a shared resource (critical section) which is being held by some other process. In this case the processes just keep waiting and execute no further; * starvation, which occurs when a process is waiting to enter the critical section but other processes keep on executing the critical section and the first process just keeps on waiting; * priority inversion, which occurs when a high priority process is in the critical section, it may be interrupted by a medium priority process. This is the violation of rules but this may happen and may lead to some serious consequences when dealing with real-time problems; * busy waiting, which occurs when a process is waiting for its turn but is at the same time continuously checking to see if it is now its turn to process or not. This checking is basically robbing the processing time of other processes. Processes access to critical section is controlled by using synchronization techniques. This may apply to a number of domains. 抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「Synchronization (computer science)」の詳細全文を読む スポンサード リンク
|