Created
September 23, 2009 20:26
-
-
Save cgrand/192256 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; philosophers must be initialized to 0 | |
(defn behave [qty id] | |
(when (pos? @rounds) (send-off *agent* behave id)) | |
(or | |
(dosync ; Initiate transaction | |
(when (and | |
(pos? @rounds) ; Is there more food? | |
(> 5 (rand-int 10)) ; Do I want to eat or think? | |
(got-forks? id)) ; Are both of my forks available? | |
(handle-forks id :take) | |
(alter rounds dec) | |
(send logger debug id "ate " @rounds) | |
(handle-forks id :release) | |
(inc qty))) | |
(do | |
(send logger debug id "thinks " @rounds) | |
qty))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment