Why It Gets Worse: Shared Data

In this lesson, you will see how sharing data between threads can become problematic.

We'll cover the following

The simple thread example you saw in the last lesson was useful in showing how threads are created and how they can run in different orders depending on how the scheduler decides to run them. What it doesn’t show you, though, is how threads interact when they access shared data.

Interaction of threads

Let’s imagine a simple example where two threads wish to update a global shared variable. The code you’ll study is in the coding widget below.

Get hands-on with 1200+ tech skills courses.