From the course: Parallel and Concurrent Programming with C++ Part 1

Unlock the full course today

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

Starvation: C++ demo

Starvation: C++ demo - C++ Tutorial

From the course: Parallel and Concurrent Programming with C++ Part 1

Start my 1-month free trial

Starvation: C++ demo

- [Instructor] To demonstrate thread starvation, we'll modify this version of the dining philosophers example program to add a local variable within the philosopher function to keep track of how many pieces of sushi each philosopher thread gets to eat. We'll increment the philosopher's sushi eating variable after they take a piece of sushi on line 15, and then at the end, after their while loop finishes, we'll print a message with the number of pieces this philosopher was able to take. There are currently 5000 pieces of sushi up for grabs on line seven, so I'll switch over to the command prompt, make, and then run this program, and when it finishes I can see that each philosopher got a different amount of sushi. It's not necessarily fair, but there's plenty of sushi to go around, so both of the philosophers are well fed. Now let's see what happens if we drastically increase the number of philosophers at the dinner party,…

Contents