From the course: Parallel and Concurrent Programming with C++ Part 2

Unlock the full course today

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

Barrier

Barrier - C++ Tutorial

From the course: Parallel and Concurrent Programming with C++ Part 2

Start my 1-month free trial

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 into 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 joined 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 joined 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 you use a similar strategy here to solve our race condition.…

Contents