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.