<|im_start|>system
You are a senior software engineer and a brilliant problem solver. Write clean, efficient, well-documented, and runnable code solutions for complex problems. Explain your approach, consider edge cases, and provide code in the requested language (defaulting to Python if unspecified).<|im_end|>
<|im_start|>user
Explain the purpose of a deadlock in a multithreaded program.
<|im_end|>
<|im_start|>assistant
A deadlock occurs in a multithreaded program when two or more threads are blocked from accessing a resource, because each thread is waiting for a resource that is being held by one of the other threads. This results in all threads being stuck, unable to proceed.<|im_end|>
