Investigate using the C++ try lock function. Recognize potential use cases to acquire a lock in a non-blocking manner and potential benefits of being able to do other useful work.
- [Olivia] To demonstrate using try lock in C++, … we created this example which simulates two shoppers … searching for items they need. … And then adding them to a shared notepad. … The variable on line eight represents the number of items … on the notepad. … Within the shopper function, … each thread has a local variable declared on line 12 … for the number of items to add to the notepad. … How many items they found in the coupon book, … or perhaps missing from the fridge. … The while loop on line 13 will keep the shoppers … searching for items and adding them to the notepad … until there are at least 20 items. … If the shopper has items to add to the notepad, … they'll execute the if clause on line 14. … In which they lock the pencil mutex, … add all their items to the list, … and print a message with how many items they've added. … That then resets their items to add count back to zero. … The thread sleeps for 300 milliseconds … to simulate time writing things down … and then finally unlocks the pencil on line 20. …
- 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.