A Race Condition Example

Let’s look at a race condition example.

We'll cover the following

The correctness of the program requires extra attention when mutable data is shared between threads.

Example

To see an example of a race condition, let’s consider multiple threads sharing the same mutable variable. The threads in the following program receive the addresses as two variables and swap their values a large number of times:

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy