Monday, October 12, 2009

Race condition, Dead lock, Live Lock and Starvation in multithreaded applications

Race Condition


A race occurs when two or more threads in a mutithreaded program try to access the same shared data and at least one of the accesses is a write operation. Races are hard to identify. The consequences will be visible at a much later time or even in totally different part of the program itself.

Deadlock

A deadlock occurs when two or more threads wait on each other, forming a cycle and preventing all of them from making any forward progress. Deadlocks are usually introduced by developers trying to solve the race conditions.

Starvation

Starvation is an idefinite delay or permanent blocking of one or more runnable threads in a multithreaded application. hreads that are not being scheduled to run even though they are not blocking or waiting on anything else are said to be starving.

Livelock

Livelocks occur when threads are scheduled but are not making forward progress because they are continuously reacting to each other's state changes. High CPU utilization with no sign of real work being done is a classic warning sign of a livelock. Livelocks are incredibly difficult to detect and diagnose.

3 comments: