From the course: Parallel and Concurrent Programming with C++ Part 1
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Deadlock - C++ Tutorial
From the course: Parallel and Concurrent Programming with C++ Part 1
Deadlock
- Olivia and I decided to take a snack break to demonstrate some of the problems that can occur when using locks. A classic example that's used to illustrate synchronization issues when multiple threads are competing for multiple locks is the dining philosopher's problem. In this scenario, Olivia and I are two philosophers or threads doing what philosophers do best, thinking and eating. We both need to access a shared resource, this plate of sushi, and each time one of us takes a piece of sushi, we're modifying its value, the number of pieces that are left. The act of taking sushi from the plate is a critical section. So to protect it we've devised a mutual exclusion process using these two chopsticks at mutexes. When I want to take a bite of sushi, I'll first pick up the chopstick closest to me to acquire a lock on it. Then I pick up the farther chopstick. Now I have possession of both locks. I'm in the critical…
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.