Mod 2: Sync Problems Patterns Flashcards
What are the most common issues with synchronization?
(1) Race Condition
(2) Deadlock
(3) Livelock
(4) Starvation
How can synchronization be done?
(1) Mutual Exclusion
(2) Condition Synchornization
When does a race condition typically happens?
When more than one threads get access to a shared resource at the same time
What can a race condition cause?
Faulty and corrupt data
What can we solve race conditions?
Execute the critical section in an atomic operation to ensure thread safety
What is “starvation”?
When an action in a concurrent programming situation never get executed, i.e when a thread is unable to gain access to a shared resource
When does “starvation” occur?
When shared resources are made unavailable for long period of time by “greedy” threads
How do we avoid starvation?
By letting every thread get a fair amount of time, something that is usually a task for the OS scheduler and not something we neccessarily can affect
What is “deadlock”?
When two or more threads are blocked forever, waiting “deadly” for each other
What is “livelock”?
Livelock occurs when two or more threads is spinning while waiting for a condition that will never become true
eg. threadA is waiting for threadB, and threadB are waiting for threadA
What is the difference between livelock and deadlock?
Thread in deadlock are in a waiting-state and threads in livelock are in a running-state
What is a “barrier”?
Synchronization points that processes/threads must reach before any of them are allowed to proceed
What does a safety property mean?
That each process/thread should never enter a bad state, i e. state in which some variables have faulty values, to avoid corrupt shared data
What does a liveness property mean?
That each process/thread should have liveness property, i e. process/thread eventually enter a good state, in which variables have correct values
What are examples of safety propeties?
Mutual exclusion and absence of deadlock