Created
October 19, 2017 12:51
-
-
Save graninas/2e172aa210209873134d6d773da86417 to your computer and use it in GitHub Desktop.
Dining philosophers and STM
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
takeFork :: TVar Fork -> STM () | |
takeFork tvFork = do | |
fork <- readTVar tvFork | |
case fork of | |
InUse -> retry | |
Free -> writeTVar tvFork InUse | |
makeDiningPhilosopher :: TVar Fork -> TVar Fork -> STM (TVar Philosopher) | |
makeDiningPhilosopher leftFork rightFork = do | |
takeFork leftFork | |
takeFork rightFork | |
newTVar Dining |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment