Deadlock - Chapter 7
Threads can request resources such as IO or memory.
To get a resource:
- Request
- Use
- Release
Deadlock - when two or more threads both want resources that the other has a lock over
Livelock - when a thread keeps attempting a action that fails (i.e. two people trying to pass each other in a hallway)
What causes deadlock
Mutual exclusion - when only one (or limited) thread can hold a resource at a time
Hold and wait - when a thread is holding a resource and is waiting for another
No preemption - when a thread can only be released voluntarily
Circular wait - when each thread is waiting for a resource the next thread is holding in a circular fashion
Examples of deadlocks or not deadlocks with graphs
Not deadlock

Deadlock

Not deadlock (since p4 can be freed up)

How to stop deadlocks
- Dont bother (common option)
- Kill threads until the problem resolves
- Dont let one of the 4 causing factors above happen
- ... more in the book