educative.io

Clarification needed

In this lesson, the very first line mentioned " Both issues from the previous lesson are actually race conditions", could you please elaborate on this? What are those issues? I have gone through earlier lesson, but I don’t see any scenario of race condition?

The outcome of the program depends on the interleaving of the threads in two ways.

  1. The created thread has not enough time to display its id.
  2. The created thread has not enough time to calculate the sum.

The second race condition is a data race because the created thread writes the shared variable (line 11) and the creator thread reads the shared variable (line 26).

1 Like