Occurs when there is missing:
Can be very difficult to locate
How well you can spot a race condition is an index of how good a concurrent programer you are.
It is an indefinite postponement of "you go first" on simultaneous arrical of tasks.
Caused by poor scheduling in entry protocol
A task does not get executed because it is never on top of the priority list.
Long-term (infinite) starvation is extremely rare.
It is a state where one or mroe processes are waiting for an event that will not occur.
unlike live-lock and starvation, the program does not consume CPU time.
Failure in cooperation.
int main(){
uSemaphore s(0); // start closed
s.P(); // wait for lock to open
// but there is no thread that can V on s for the main.
}
Failure to acquire a resource protected by mutual exclusion
Also called a "Grid-Lock" in traffic situation.
To prevent the grid-lock, you must not acquire mutual exclusion unless you can fully pass the intersection.
There are 5 conditions for such deadlock to occur
Like barging avoidance, this method will allow the deadlock condition to occur.
It allows the program to enter unsafe state but keep it away from deadlock.
Better resourec utilization than deadlock prevention.
Demonstrate a safe sequence of resource allocations that does not end up in deadlock
Requires a process state its maximum resource needs
steps
upon request for resources, run the above step and see if you have a sequence of tasks. If not, you are in a danger place and should not allow allocation of that resource.
have a bipartite graph of tasks and resources
The red line is a request for acquiring a resource.
If there is a cycle in the graph, it may result in deadlock.
If T4 finishes and frees one of R3, T2 gets that R3, so it will not end up deadlock.
To do this, we can either
make an isomorphic graph
which is not easy
apply banker's algorithm.
This can be expensive to apply for all resource allocation within the system
Let the deadlock happen and recover it later.
To do this, we need a way to:
This can much cheaper than avoiding deadlock.
There is uC++ debugging macros to locate deadlock.
The question is "what do you do with preempted task"
There is no easy option :/
The task that has been preempted may have been holding the resources because it was modifying it.