Investigate the dining philosophers scenario with an example C++ program. Implement a simple solution to resolve the deadlock by prioritizing the order in which each of the available locks will be acquired.
- To demonstrate a deadlock, … we've created this example program … that simulates two dining philosophers … thinking and eating sushi. … The philosopher function on line nine … takes two reference parameters named first chopstick … and second chopstick, which indicate the order … in which the philosopher will lock the two mutexes. … The while loop on line 10 will continue to run … as long as the sushi count variable is positive, … which represents the amount of sushi left … on the shared plate between the philosophers. … We initialize the sushi count to 5,000 on line seven, … so our two philosophers should both end up very well fed. … Within the while loop, the philosopher will pick up … and acquire a lock on their first chopstick … followed by their second chopstick, … at which point they're in the critical section. … If there's still sushi left on the plate, … they'll take a piece by decrementing … the sushi count variable online 14, … then finally unlock both chopsticks … to put them down for someone else to take. …
- 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.