From the course: Parallel and Concurrent Programming with C++ Part 2
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Latch: C++ demo - C++ Tutorial
From the course: Parallel and Concurrent Programming with C++ Part 2
Latch: C++ demo
- [Instructor] In addition to barriers to control the order of execution, there's another related synchronization mechanism called a latch. This allows one or more threads to wait until a set of operations being performed in other threads to complete. The latch is initialized with a given count value, which threads can use in two ways. Threads can either wait at a latch until the count value reaches zero, much like how threads can wait at a barrier, or they can decrement the count value by calling the latch's count_down function. So, the key difference between a latch and a barrier is that the barrier releases when a certain number of threads waiting on it has been reached, whereas the latch releases after the count_down function gets called enough times to reduce the count value to zero. For this demonstration, we'll modify the previous example code that used a barrier to now use a latch instead. First, we'll change the…
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.