- Exercises

In this exercise, you will spot a data race and synchronize the code.

We'll cover the following

Task 1

In the code below, vary the sleep time of Sleeper to prevent undefined behavior.

Variation in the runtime with no synchronization results in undefined behavior.

The program has one serious issue: it has a data race and, therefore, undefined behavior. In simple words, a data race is a situation in which you have concurrent, non-synchronized read and write access to data. Do you spot the data race?

Get hands-on with 1400+ tech skills courses.