Multithreading Issues: Deadlocks, Livelocks, and Starvation
Hi everyone, welcome back. In this article, I’ll go over some common issues that may occur while working on a project that uses multithreaded programming.

Multithreaded Programming
What is multithreaded programming? Simply put, you can think of a thread as a set of instructions to run in your program. Multithreading occurs when more than one thread is executed at the same time. A number of headache inducing issues may occur when attempting to write a multithreaded program. Some common issues include deadlocks, livelocks, and starvation.
Deadlock
A deadlock occurs when two threads are stuck waiting on each other. Say that thread A is programmed to take an action after thread B performs an action and that thread B is programmed to take an action after thread A takes their action, but neither one performs an action, then that’s a deadlock. Because thread A is waiting for thread B and thread B waiting for thread A, no progress is happening and the process is stuck.
For instance, let’s say that person A is waiting for person B to give them a hammer and person B is waiting for person A to give them a hammer, but neither person has a hammer. Then person A and person B are stuck waiting forever, being a deadlock.
Livelock
Livelocks are similar to deadlocks except that being stuck waiting on each other, the threads are constantly repeating the same actions over and over again based off of each others actions. Thread A is programmed to take an action immediately after thread B takes an action and thread B is programming to take an action immediately after thread A takes their action. Because they respond to each other’s actions, they are stuck in a livelock.
For instance, let’s say that person A will automatically give their hammer to person B once they have a hammer and that person B will automatically give their hammer to person A once they have a hammer. If a hammer is given to person A, then they pass it to person B, then they pass it back to person A, then back to B, and it keeps going back and forth.
Starvation
Starvation occurs due to resource prioritization. When there are many threads running on the same shared resource pool, the threads are prioritized and threads with high priority will be executed before threads with lower priority. But when threads with higher priorities keep being invoked, the threads with lower priority don’t have a chance to be executed causing these threads to ‘starve’. The threads with lower priority may need to run eventually, but if they don’t ever get the chance to be executed, it could cause problems later.
Conclusion
This concludes some general information about deadlocks, livelocks, and starvations. I hope this helps and wish you luck on your multithreaded program. Thanks for reading.