

You are responsible for a multi-threaded application that runs continuously and coordinates access to shared resources such as locks, queues, and device interfaces. Recently, the service has intermittently stopped making progress even though CPU and memory look normal, and thread dumps show multiple threads waiting on each other. The issue is hard to reproduce and affects system availability when it happens.
What is a deadlock, what are its four necessary conditions, and how would you prevent it in a multi-threaded application? Explain how you would verify that your prevention approach works in practice.
You are responsible for a multi-threaded application that runs continuously and coordinates access to shared resources such as locks, queues, and device interfaces. Recently, the service has intermittently stopped making progress even though CPU and memory look normal, and thread dumps show multiple threads waiting on each other. The issue is hard to reproduce and affects system availability when it happens.
What is a deadlock, what are its four necessary conditions, and how would you prevent it in a multi-threaded application? Explain how you would verify that your prevention approach works in practice.