Hehe, great idea, I like it ;-)
There does seem to be some problems with this solution though.
When I run it with 1.1.2, I always get one single gopher eating at a time
and in increasing gopher# order:
1, then 2, then 3, 4, 5, ...
With 1.2rc1, the order is not 1,2,3,4,5 anymore, but I still get only one
gopher eating at a time !
looking-up the Dining Gophers, heuu, Philosophers on Wikipedia,
the shown example of a failing solution (deadlocks) looks *a lot* like what
we have here unfortunatlyhttp://en.wikipedia.org/wiki/Dining_philosophers_problem
Here is a modified version, tryong out the "Resource hierarchy solution".
(i.e the 1st suggested solution on wikipedia)http://play.golang.org/p/ywiDs9WkWt
1) I added some 'thinking' time after eating (algorithm does not seem to
work w/o it !! any ideas why !?)
2) removed the 'extra' goroutines
for example, by using a buffered channel (len=1) we can directly 'feed
the spoon channel' (ouch, sorry about that one hihi)
3) I left the runtime.GOMAXPROCS code in, but I believe it is not necessary
(read here before that sometimes it can make code run slower)
what do you all think ?
I might look at the other suggested wikipedia solutions for fun
On Sunday, 22 September 2013 19:28:09 UTC-4, Sonia Keys wrote:
One problem is that it allows deadlocks. Run the program enough times and
you'll see that once in a while it produces no output as each gopher grabs
one fork and they all sit and wait for the timeout.
On Saturday, September 21, 2013 12:11:01 AM UTC-4, Karan Misra wrote:
So, trying to learn the nuances of Go concurrency by attacking the Dining
But to get a measure of speed, better to locally run it with a command
go run dining_gopher.go -count 10 -delay 10
This will utilize all cores on your machine and allow parallel "eating."
I was able to simulate a run with over 10000 philosophers and it was
running super fast (I didn't try and higher number.)
1. Is this solution valid?
2. Obvious improvements?
Any all constructive comments are welcome.
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to email@example.com.
For more options, visit https://groups.google.com/groups/opt_out.