From the course: Python Parallel and Concurrent Programming Part 1

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Deadlock: Python demo

Deadlock: Python demo - Python Tutorial

From the course: Python Parallel and Concurrent Programming Part 1

Start my 1-month free trial

Deadlock: Python demo

- [Narrator] To demonstrate a deadlock with a dining philosophers problem and how to resolve it will expand our scenario from having just two philosophers, Olivia and me, to having three philosophers. Olivia, me and our buddy Steve, each competing for two of the three chopsticks placed around the table, labeled here as A, B and C. In our example Python program, we instantiate those three lock objects on lines six through eight and name them chopstick A, B, and C. We also create a variable named sushi count to represent the amount of sushi left between the philosophers. Below that, the philosopher function on line 11 is used to represent our philosopher's who think and eat sushi. The function has three input parameters. The philosopher's name and two locks, named first chopstick and second chopstick to indicate the order in which the philosopher will acquire them. The while loop on line 13 will make the philosopher…

Contents