From the course: Parallel and Concurrent Programming with Java 2
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Barrier - Java Tutorial
From the course: Parallel and Concurrent Programming with Java 2
Barrier
- To prevent our race condition from occurring, we need a way to synchronize our actions so we execute our respective multiplication and addition operations in the correct order. And we can do that with something called a barrier. A barrier is a stopping point for a group of threads that prevents them from proceeding until all or enough threads have reached the barrier. I like to think of threads waiting on a barrier like players on a sports team coming together for a huddle. Before they join the huddle, the players might be doing other things, putting on their equipment or getting a drink of water. As they finish those individual activities, they join their teammates at the huddle. Players in the huddle wait there until all of their fellow teammates arrive. Then they all yell, "Break," and then they scatter about to continue playing their game. - We can use a similar strategy here to solve our race condition, huddling…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.