Data synchronization refers to the process of ensuring that data in two or more locations or systems is consistent and up-to-date. This is often necessary when data is stored in multiple locations, such as in a distributed database or in different applications that need to share data. Data synchronization can be achieved through various techniques such as replication, mirroring, or using a shared database.
Process synchronization
Process synchronization, on the other hand, refers to the coordination of multiple processes or threads to ensure that they access shared resources in a mutually exclusive and synchronized manner. This is important to prevent conflicts and inconsistencies that can arise when multiple processes or threads try to access and modify the same resource simultaneously.
synchronization is needed when:
Agree on the ordering of events
Access a shared resource
synchronization challenges:
Coordination of actions that depend on communication over a network(networks are not always reliable)
A message will not arrive at its destination before it is sent
If a and b in same process, a occurs before b, then a->b
If a is sent by one process and b received by another process, then a->b
If a->b b->c then a->c (a->b means a happens before b)
If two events happen in different processes that do not exchange messages, then x->y and y->x are both not true. These events are said to be concurrent, which simply means that nothing can be said (or need be said) about when the events happened or which event happened first
Centralised Lock Server and Mutual Exclusion Locks(Mutex)
Two Phase Commit Algorithm
Electing a Coordinator Node
Bully Algorithm
P sends an ELECTION message to all nodes above
If no one respond P is the coordinator
If one of the higher-numbered nodes Q answers, P concedes that it is not the winner, Q begins the election process again until one node eventually wins
Cristian’s Algorithm
The Berkeley Algorithm
Deadlock
Deadlock occurs when four particular conditions hold simultaneously in a system
Mutual exclusion: only one process can use that resource at a given time
Hold and wait: wait for a process to release something
No pre-emption: once a process has acquired a resource, nothing can force it to relinquish that resource; it has to do so voluntarily