Investigate using the C++ shared mutex class to enable multiple threads to simultaneously read within a critical section while only allowing one thread at a time to write.
- [Narrator] The shared mutex class has been part … of the standard library since C plus plus 17 … to provide a mutex that can be acquired in a shared mode … in which multiple threads can share ownership … of the mutex as well as an exclusive mode … in which only one thread can have a lock … on the mutex. … To demonstrate using a shared mutex, … this example program creates 10 threads … to concurrently read what day it is from a shared calendar … while two other threads update it. … The calendar here is just an array of strings … to represent the days of the week on line eight, … as well as an integer to indicate which day today is … on line nine. … We've created a single regular mutex named Marker … on line 10, which all of the threads will use … to enforce mutual exclusion when interacting … with the today variable. … There are two functions on lines 12 and 21 … for the threads that will be reading the calendar value … and those that will be writing to update it. … They both use a for loop to perform their action …
- Parallel computing architectures
- Shared vs. distributed memory
- Thread vs. process
- Execution scheduling
- The thread lifecycle in C++
- Mutual exclusion
- Locking in recursive and shared mutexes
- Acquiring a lock on a mutex with a try lock
- Resolving deadlock and livelock conditions
Skill Level Advanced
1. Parallel Computing Hardware
2. Threads and Processes
3. Mutual Exclusion
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.