Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

removed extraneous select

  • Loading branch information...
commit 332f89986850e63303a0d1b6d6608fa2a95a05f5 1 parent 9bb10b2
@doug authored
Showing with 7 additions and 12 deletions.
  1. +7 −12 dining-philosophers.go
View
19 dining-philosophers.go
@@ -38,20 +38,15 @@ func (phil *Philosopher) eat() {
func (phil *Philosopher) getChopsticks() {
timeout := make(chan bool, 1)
go func() { time.Sleep(1e9); timeout <- true }()
+ <-phil.chopstick
+ fmt.Printf("%v got his chopstick.\n",phil.name)
select {
- case <-phil.chopstick:
- fmt.Printf("%v got his chopstick.\n",phil.name)
- select {
- case <-phil.neighbor.chopstick:
- fmt.Printf("%v got %v's chopstick.\n",phil.name,phil.neighbor.name)
- fmt.Printf("%v has two chopsticks.\n",phil.name)
- return
- case <-timeout:
- phil.chopstick <- true
- phil.think()
- phil.getChopsticks()
- }
+ case <-phil.neighbor.chopstick:
+ fmt.Printf("%v got %v's chopstick.\n",phil.name,phil.neighbor.name)
+ fmt.Printf("%v has two chopsticks.\n",phil.name)
+ return
case <-timeout:
+ phil.chopstick <- true
phil.think()
phil.getChopsticks()
}
Please sign in to comment.
Something went wrong with that request. Please try again.