Thanks for these videos. I have been studying by reading a chapter in the Stallings book first and then watching the corresponding video(s) on your channel. I wish you had a video for every subject!
this is because P0 will always have priority over F0, therefore it it's not first come first serve. so P4 will eat less often then the rest leading to the thread being "starved". starved in the concurrent definition, not literally starved.
But no philosopher has "priority", they just have a fork that they will go for first. In the same way that P0 will go for F0 first, P4 will also go for F0 first. It's true that in this way F0 is unique as it has two philosophers that will go for it first, whereas F1, 2, and 3 only each have one philosopher that will go for them first. No philosopher will go for F4 first. I can't figure out if all that means some philosophers may be starved vs others, or whether it all evens out in the end as all philosophers always need to acquire two forks to eat anyway. I'd appreciate it if someone could provide a definitive answer.
If p4 is waiting to take f0 because p0 claimed it (or vice-versa), then it will be able to immediately take f0 as soon as the other philosopher is done because the semSignal command is an explicit invitation to take the newly released resource. There may be some small bias in who gets f0 first, but from that point onward, if demand for f0 is high, then the two philosophers will simply be taking turns, which is as fair as you can expect.
If you make fork = 5 and change code to have just one wait and signal where the wait decrements by two and the signal increments by 2 that would fix it as well.