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 unfortunatly
http://en.wikipedia.org/wiki/Dining_philosophers_problemHere is a modified version, tryong out the "Resource hierarchy solution".
(i.e the 1st suggested solution on wikipedia)
http://play.golang.org/p/ywiDs9WkWtnote:
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
Philosophers problem.
Gist:
https://gist.github.com/kid0m4n/6647055But to get a measure of speed, better to locally run it with a command
line like:
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.)
So:
1. Is this solution valid?
2. Obvious improvements?
Any all constructive comments are welcome.
Karan
--
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 golang-nuts+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out.