Race Condition

A critical race, and race condition (English race condition or race hazard ) is in the programming, a constellation in which depends on the result of an operation on the temporal behavior of certain individual operations. In general is the possibility of a race condition that occurs to avoid.

Unintentional race conditions are a common reason for hard to find bugs; characteristic of such situations is in fact that already the changed conditions for program testing, such as additional logging or debugging mode, can lead to a complete disappearance of symptoms. To avoid such situations, for example, semaphores can be used when creating the program.

Example

Two concurrent systems aim to increase the same value. The necessary individual steps that have to go through each of the two systems are:

Suppose the value amounts to initially 1 The first system is called " A", the second system "B". Both systems, make the value of the expected new value is 3 If system A time works against system B, which will be as follows:

Working both systems simultaneously and the order of the commands undetermined, the race condition but may cause the actual received new value instead of 2:

To avoid the problem would have access to the value A lock until completion of the change so that B must wait until A has completed its access to the value.

668446
de