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.
Starvation: Python demo - Python Tutorial
From the course: Python Parallel and Concurrent Programming Part 1
Starvation: Python demo
- [Instructor] To demonstrate thread starvation in Python we'll modify the dining philosophers example by adding a local variable within the philosopher function to keep track of how many pieces of sushi each philosopher thread gets to eat. I'm going to name that sushi_eaten and I'll initialize it to zero. We'll increment the sushi eaten variable every time the philosopher takes a piece of sushi. sushi_eaten += 1, and at the end of the philosopher function after the while loop had finished we'll print out the number of pieces that it took. print(name), 'took', sushi_eaten, 'pieces' There are currently 5000 pieces of sushi up for grabs on line 9, so I'll switch over to a command prompt and run this program. (keys clacking) When it finishes, we see that each of the three philosophers got a different amount of sushi and it's not particularly fair. Olivia took way more sushi than Barron or Steve. She has over 3000 of the…
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.