Saturday, 26 December 2015

Types of Synchronizations

To avoid the race conditions in Parallel Programming there are two types of synchronizations between threads (Process).
1). High Level Synchronizations.
2).  Low Level Synchronizations.

  These kind of methods are useful for the shared memory computers.

Difference between High and Low Level Synchronizations

  Low level synchronizations affects one thread only where high level synchronizations affects many threads.

1. High Level Synchronizations Types

- Critical
  What critical does is mutually exclusion. The idea is to create one critical section, and this section can only executes one thread at a time. If one thread already code of that section then thread will wait until it completes the execution.

Atomic Access
  In programming, an atomic action is one that effectively happens all at once. An atomic action cannot stop in the middle: it either happens completely, or it doesn't happen at all. No side effects of an atomic action are visible until the action is complete. The atomic access is need for the general binary operations like a++, because it  does not describe an atomic action. Declaring an block of code atomic guarantees that operations made on the variables occur in an atomic fashion, i.e., that all of the substeps of the operation are completed within the thread they are executed and are not interrupted by other threads.

  Barrier is the point in program at which threads stop and wait. When all the threads have reached the barrier, they can proceed. Synchronization barriers are useful for phased computations, in which threads executing the same code in parallel must all complete one phase before moving on to the next. Example - Suppose you have a null array of size 100. Your system can make only two threads to write data and to shift the data on the left side. So first of all you divide the array between two threads to write the data and then put the barrier on it to complete the phase of read data. After that if both the thread reach at the same barrier point then only able to shift the data.

  Every execution has a synchronization order. A synchronization order is a total order over all of the synchronization actions of an execution. For each thread t, the synchronization order of the synchronization actions in t is consistent with the program order of t.

2. Low Level Synchronizations

- Flush
  Used to make a thread's view of shared data consistent with main memory. Shared data are stored in main memory locations that are supposed to be accessible by all threads. The modified data has to be stored in main memory before the flush can complete, and unchanged data has to be read again from the main memory after the flush is complete. Flush allows us to keep memory consistent in a cross platform way.

- Locks

No comments:

Post a Comment