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.
Barrier - C++ Tutorial
From the course: Complete Guide to Parallel and Concurrent Programming with C++
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 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 together to synchronize when we each execute our operations to add…
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.