From the course: Python Parallel and Concurrent Programming Part 1

Unlock the full course today

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

Abandoned lock: Python demo

Abandoned lock: Python demo - Python Tutorial

From the course: Python Parallel and Concurrent Programming Part 1

Start my 1-month free trial

Abandoned lock: Python demo

- [Narrator] To demonstrate what happens if a lock gets abandoned in Python, we'll be modifying the previous dining philosophers example that we used to demonstrate a dead lock with three philosophers using chopsticks to take sushi from a shared plate. We've already fixed the dead lock in this version of the code, so if I run this program, the philosophers successfully take turns eating sushi until all 500 pieces are gone. The critical section for this program exists between the acquire methods on lines 14 and 15 and the release methods on lines 21 and 22. Now, if one of the philosopher's threads acquires the locks, and then something goes wrong in that critical section to cause an unexpected error, that could kill its thread before it gets a chance to release the lock. To simulate that happening, I'll add another if statement to check if there are exactly 10 pieces of sushi left, and if so, I'll do my favorite technique…

Contents