summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--forks.go11
-rw-r--r--philo.go4
2 files changed, 5 insertions, 10 deletions
diff --git a/forks.go b/forks.go
index ba57ef7..d45fd3b 100644
--- a/forks.go
+++ b/forks.go
@@ -15,11 +15,10 @@ func NewForks(n int) []Fork {
return forks
}
-func (f Fork) Grab() {
- <-f
-}
+func (f Fork) Put() { f <- struct{}{} }
+func (f Fork) Get() { <-f }
-func (f Fork) TryGrab(d time.Duration) bool {
+func (f Fork) TryGet(d time.Duration) bool {
select {
case <-f:
return true
@@ -27,7 +26,3 @@ func (f Fork) TryGrab(d time.Duration) bool {
return false
}
}
-
-func (f Fork) Put() {
- f <- struct{}{}
-}
diff --git a/philo.go b/philo.go
index 930b23f..7007a7a 100644
--- a/philo.go
+++ b/philo.go
@@ -37,8 +37,8 @@ func (p Philo) Arrive() stateFn {
func (p Philo) Hungry() stateFn {
p.Print("is hungry")
- p.Left.Grab()
- if ok := p.Right.TryGrab(p.TimeOut); ok {
+ p.Left.Get()
+ if ok := p.Right.TryGet(p.TimeOut); ok {
return p.Eat
}
p.Left.Put()