First page Back Continue Last page Overview Graphics

Race conditions

What happened?

The problem is, that the statements

x += 1

and

x 1= 1

are not atomar.

In one thread, we are calculating x += 1 e.g.

To this this the value of x is retrieved to calculate “x + 1”.

It can happen now, that another thread also needs and fetches the value of x before the first thread has written back the incremented result!

This is known as “race condition”