Y
Yan Zhou
Hi there,
I have code a program that solves the dinning philosopher problem. But there
is still room to improve.
My solution is to acquire both forks at any given time. If a philosopher
first gets the left fork, and then tries to get the right fork, that may
risk starvation.
The current solution locks on the list object (which contains all fork
objects). Thus, only one philosopher can acquire two forks at any given
time, and multiple philosophers can eat at the same time. Once a philosopher
acquires the forks, they are removed from the list; and philosopher returns
the forks to the list after he finished eating.
I would like to enhance the program so that multiple philosophers can get
the forks at the same time. And I still want to ensure that a philosopher
always get two forks at once. This is more difficult because I can no longer
lock on the list object which contains forks since multiple phiolosophers
must be allowed to remove/add forks to the list. I do not have an elegant
solution for this.
Any suggestion?
Yan
I have code a program that solves the dinning philosopher problem. But there
is still room to improve.
My solution is to acquire both forks at any given time. If a philosopher
first gets the left fork, and then tries to get the right fork, that may
risk starvation.
The current solution locks on the list object (which contains all fork
objects). Thus, only one philosopher can acquire two forks at any given
time, and multiple philosophers can eat at the same time. Once a philosopher
acquires the forks, they are removed from the list; and philosopher returns
the forks to the list after he finished eating.
I would like to enhance the program so that multiple philosophers can get
the forks at the same time. And I still want to ensure that a philosopher
always get two forks at once. This is more difficult because I can no longer
lock on the list object which contains forks since multiple phiolosophers
must be allowed to remove/add forks to the list. I do not have an elegant
solution for this.
Any suggestion?
Yan