Рет қаралды 13,173
►Full Series Playlist: • Modern C++ (cpp) Concu...
►Find full courses on: courses.mshah.io/
►Join as Member to Support the channel: / @mikeshah
►Git Repo: github.com/MikeShah/moderncpp...
►Lesson Description: In this lesson I teach you about how to use a condition_variable in C++. This is a relatively old concept that is useful for making sure that cpu time is not wasted attempting to constantly 'try' to acquire a lock.
00:00 Synchronization of threads with locks
1:20 Wasted cpu cycles waiting
1:58 Introduction to condition variable
3:20 What is needed for condition variables
4:21 Worker and reporter thread idea
5:00 Implementation of condition variable
5:45 Setting up condition variable
6:30 Setting up our 2 threads
7:20 Setting up worker thread
8:07 Using a unique_lock
9:20 Doing work in reporter thread and updating condition
10:50 notify with condition variable
11:58 Setting up reporting thread
12:46 Condition variable wait
13:20 wait blocks a thread
14:04 notify wakes up a thread
14:34 Syntax fixes
15:08 Logic fixes
15:40 Successful execution of program
16:10 Explanation again of what we have done
►KZfaq Channel: / mikeshah
►Please like and subscribe to help the channel!