Open akaigoro opened 9 years ago
Hi Alexei,
Possible, I think, but I don't think it's a great FBP application. I tend to think of an FBP app as being more like a network of concurrently running machines connected via conveyor belts. In the case of the dining philosophers, I don't know where the conveyor belts go!
So, yes, each philosopher is probably a process, but I'm afraid the chopsticks look to me more like mutexes or semaphores (?). Let's see...
Philosopher:
do forever
do forever
if lefthand chopstick (synchronized) available
grab chopstick on left
break
else
wait random interval
endif
enddo
do forever
if righthand chopstick (synchronized) available
grab chopstick on right
break
else
wait random interval
endif
enddo
wait random interval (eating)
release chopsticks
wait random interval (outside room)
enddo
Not sure if this makes sense!
I suppose the chopsticks could be processes, but that approach seems even more complex to me...!
Best regards,
Paul
On Sun, Jun 14, 2015 at 2:13 PM, Alexei Kaigorodov <notifications@github.com
wrote:
Can Dining Philosophers problem be implemented in JavaFBP?
— Reply to this email directly or view it on GitHub https://github.com/jpaulm/javafbp/issues/6.
I suppose chopstick as process may have 2 input ports: one for signal that chopstick is free and one for requests from philosophers. Request contains reference to a philosopher's port where he waits for chopstick. As soon as both chopsticks ports are filled, chopstick's manager sends a signal to the philosopher who issued the request.
My guess would be: one input port to receive requests for the chopstick and notification of its availability (because the diner has finished) , and an output port to tell the requester that s/he now has use of the chopstick!
I think I would have to build the thing to see whether that works - I usually learn better by doing!
Best regards,
Paul
On Tue, Jun 16, 2015 at 3:16 PM, Alexei Kaigorodov <notifications@github.com
wrote:
I suppose chopstick as process may have 2 input ports: one for signal that chopstick is free and one for requests from philosophers. Request contains reference to a philosopher's port where he waits for chopstick. As soon as both chopsticks ports are filled, chopstick's manager sends a signal to the philosopher who issued the request.
— Reply to this email directly or view it on GitHub https://github.com/jpaulm/javafbp/issues/6#issuecomment-112533470.
I have drawn what I think might be the flow for this problem, bearing in mind that, when two kinds of input might be arriving asynchronously at one process, it is usually better to bring them into one input port. I think this might be overkill for this problem though!
Regards,
Paul
Can Dining Philosophers problem be implemented in JavaFBP?