Week 4 - Synchronization Flashcards
Other types of synchronization
thread i sends a message to thread j:
recieve operation in thread j cannot complete until send operation in thread i is reached.
Send cannot complete until thread j reaches recieve.
Join Synchronization: between parent and child threads. completes operation in parent when child terminates.
Barrier Synchronization:
across a group of N processes. no thread completes its barrier operation until all N threads have reached their barrier operation.
General Synchronization
consists in a particular thread having to wait until some condition is created by one or more other threads.
Dijkstra’s semaphores
are one rather general mechanism for achieving different kinds of synchronization.
P(S) decrease semaphore, but not below zero
V(S) increase semaphore.
Notification synchronization
compare with send/receive synchronization.
Resources
Computer systems have many kinds of resources, that can only be accessed by one process or thread at a time.
example: physical devices like printers.
if two threads update a shared data structure can corrupt.
Deadlocks
Resource deadlocks can occur when processes (or threads) need to acquire access to more than one exclusive resource (printer or scanner for e.g.)
Deadlock
Deadlock is a situation where a process or a set of processes wait indefinitely for an event that can never occur.
Deadlock Modelling
Resource deadlock can be modelled using a Resource Allocation Graph, which shows:
- Which processes are requesting which resources.
- Which resources have been granted to which processes.
If graph contains no cycles = no deadlock.
If graph contains a cycle = deadlock.
Resource Allocation Graphs (Revise directed graphs. SLIDE 15,16,17)
Deadlock Detection and Recovery
Allows system to enter deadlock state.
Runs Detection algorithm periodically to check.
Performs Recovery scheme if deadlock.
To detect deadlock, search for a cycles in the Resource Allocation Graph.
Deadlock Detection
(Slide 20)
Deadlock Recovery
Crudely - kill processes until the deadlock cycle is eliminated.
“Survivors” get the resources.
Commonly used in Relational Database Management Systems, where transactions identified as causing deadlock can be “rolled back”.
Deadlock Avoidance
The idea here is to keep the system “safe” – avoid entering “unsafe” states which may later turn into a deadlock.
-classic deadlock scenario of two processes sharing resources
-Each process has its own “instruction counter”.
-If we plot these as two axes of a graph, behaviour of whole system is represented as a trajectory in this graph, moving upwards and to the right.
Two Processes and One Resource (Slide 23, 24)
Two Processes and Two Resource (Slide 25, 26)