Barrier demo: Difference between revisions

From COMP15212 Wiki
pc>Yuron
No edit summary
 
gravatar Yuron [userbureaucratinterface-adminsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPmludGVyZmFjZS1hZG1pbjxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs)
m (1 revision imported)
 
(No difference)

Latest revision as of 12:46, 26 July 2019

On path: IPC 1: Processes • 2: Interprocess Communication • 3: Shared Memory • 4: Files • 5: Unix Signals • 6: Pipes • 7: Sockets • 8: Synchronisation • 9: Synchronisation Barrier • 10: Atomicity • 11: Mutual exclusion • 12: Signal and Wait
Depends on Synchronisation

This demonstration illustrates five processes (or threads) which progress randomly and independently. However they are required to synchronise at a certain barrier point so, when a thread reaches that point – unless it is the last to do so – it is blocked and waits.

When the last thread reaches the barrier the blockage is cleared and the threads can run freely again until they complete.

This can be implemented in various ways, but for a simple illustration:

  • Before the processes diverge a (shared) variable is initialised to ‘5’.
  • When a process reaches the barrier it decrements this variable (in a safe, atomic fashion).
    • If the result is not zero the process waits.
    • If the result is zero, the process frees up all the others and continues.
      (It may, first, reset the variable if the barrier is to be used again.)