From the course: Complete Guide to Parallel and Concurrent Programming with C++

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Data race

Data race

- One of the main challenges of writing concurrent programs is identifying the possible dependencies between threads to make sure they don't interfere with each other and cause problems. Data races are a common problem that can occur when two or more threads are concurrently accessing the same location in memory, and at least one of those threads is writing to that location to modify its value. Fortunately, you can protect your program against data races by using synchronization techniques, which we'll show you later. But to eventually use those techniques, you'll first need to know how to recognize the data race. Olivia and I are two concurrent threads working together to figure out what we need to buy from the grocery store. I'll take inventory of the pantry, and when I see that we're running low on something, I'll add more of that item to our shared shopping list. - And while Baron does that, I'll look through my recipe book and I'll add ingredients to our shopping list for the…

Contents