4 ms·
This is kind of cheating. :) This solution doesn't really cover the core problem in the dining philosophers puzzle - that your philosophers can't communicate w
by danielvf 8y ago
This is kind of cheating. :)
This solution doesn't really cover the core problem in the dining philosophers puzzle - that your philosophers can't communicate with each other or some external system to coordinate!
Having a single external controlling process allocating all forks makes the whole problem trivial (at least until one of the philosopher processes crashes and never notifies the controller that they are done with the forks they were using). This solution also uses a library that provides the underlying thread-safe communication, which hides another layer of complexity.
If your problem lets you get away with this, then HECK YES, do it! This is a fantastic solution that avoids most of the resource sharing gotchas. This kind of solution pops up pretty naturally in Erlang/Elixier with extremely lightweight processes and built-into-the-language safe message passing.
If you can change the constraints a little to make a hard problem into a simple problem, do it!