Managing deadlocks and race conditions
As with many tools at a developer’s disposal, misusing features of managed threading can have adverse impacts on your applications at runtime. Deadlocks and race conditions are two scenarios that can be created because of multithreaded programming:
- A deadlock happens when multiple threads are trying to lock the same resource and as a result, cannot continue executing.
- Race conditions happen when multiple threads are proceeding toward updating a particular routine, and a correct outcome is dependent on the order in which they execute it.
Figure 3.2 – Two threads in contention for the same resources, causing a deadlock