From the course: Parallel and Concurrent Programming with Java 1

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Data race

Data race - Java Tutorial

From the course: Parallel and Concurrent Programming with Java 1

Start my 1-month free trial

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 it's 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. - While Barren does that, I'll look through my recipe book and I'll add ingredients to our shopping list for the meals…

Contents