Process Synchronisation Flashcards
Define an atomicity high level instruction.
Single operations in high level programs are often compiled into several machine instructions (atomic instructions)
Explain what is meant by concurrent programming
It is the process of interleaving (running one instruction of the sequential process) sets of sequential atomic instructions (must be correct under all possible intereleavings)
Define a race condition.
A race condition occurs when a program output is dependent on the sequence or timing of code execution. The part that is at risk is the critical section (parts of the program where shared resources are accessed)(should never split), only one processor should execute at a time. This leads to undesireable or surprising results.
What is a deterministic computation?
Computations that have the same result each time. This is better than indeterminate results. We need a mechanism to control access to shared resources in concurrent code (synchronisation is necessary for any shared data structure). We want critical sections to run with mutual exclusion (only one at a time).
What are the 5 properties of a critical section?
Mutual exclusion (one program running at a time)
Guarantee of Progress (processes outside the critical section cannot stop another from entering it)
Bounded waiting (a process waiting to enter a critical section will eventually enter, and leave)
Performance (the overhead of entering/exiting should be small)
Fair (don’t make some processes wait longer than other).
What 2 solutions are there to synchronisation?
Atomicity: atomic operations cannot be interrupted (it happens all at once), in order to avoid illogical outcomes. Basic atomicity is provided by the hardware.
Conditional Synchronisation: A mechanism that protects areas of the memory from being modified by two different thread at the same time.
A lock is an example of a solution to Mutual exclusion, explain in detail what it is, how to use it, it’s benefits and it’s limitations.
A lock is a token you need to enter a critical section of code. If a process wants to execute a critical section, it needs the lock. The Lock has 2 states (Held or not held), as well as 2 operations (acquire and release).
The lock can be used as a variable. A program could have multiple locks. Some benefits of locks are: only 1 process can execute the critical section at a time, when a process is done another process can enter the critical section and it achieves mutual exclusion. Limitations of a lock are that processes can acquire other locks and you must use the same lock for all critical sections accessing the same data.
What are the drawbacks to a spinlock?
Form of busy waiting (burning CPU time). Once acquired they are held until explicitly released (what about other processes?). It is inefficient if the lock is held for long periods.
What is a spinlock?
A lock that causes a thread trying to acquire it to simply wait in a loop (“spin”) while repeatedly checking whether the lock is available.
What is deadlock?
A situation in which processes block each other due to resource aquisition and none of the processes make any progress as they wait for the resource held by the other process.
What protocols should be introduced to avoid a deadlock?
Adding a timer to request lock method.
Adding a new check (lock) method to see if a lock is already held before requesting it.
Avoiding hold and wait protocol.
What is livelock?
A situation in which processes block each other with a repeated state change yet make no progress. Each process checks whether the other process is in an active state. If so, then it hands over the resource to the other process. However, both keep on handing over the resource to each other indefinitely.
What is starvation?
Starvation is an outcome of a process that is unable to gain regular access to the shared resources it requires to complete a task and thus, unable to make any progress.
What is a semaphore?
A type of generalised lock that has a higher level synchronisation primitive. It is implemented with a counter that is manipulated atomically via 2 operations: signal (increments counter) and wait (decrements counter).
Why are semaphores used?
To enforce mutual exclusion, avoid race conditions and implement process synchronisation.