Skip to content

Latest commit

 

History

History
44 lines (31 loc) · 699 Bytes

Lecture12.md

File metadata and controls

44 lines (31 loc) · 699 Bytes

Programowanie funkcyjne

Tomasz Brengos

Wykład 12

Kod wykładu

Basics/Lecture12.hs

DiningPhilosophers/


Współbieżność (concurrecy)

import Control.Concurrent
import Control.Monad

main :: IO ()
main = do
  forkIO $ replicateM_ 5 $ putStrLn "a"
  replicateM_ 5 $ putStrLn "b"
  getLine
  return ()

I inny przykład:

alpha = ["a", "b", "c", "d", "e"]

main2 = do
  mapM_ forkIO [ replicateM_ 3 (putStr s) | s <- alpha ]
  getLine
  return ()

Literatura

https://hackage.haskell.org/package/stm https://en.wikipedia.org/wiki/Dining_philosophers_problem https://www.oreilly.com/library/view/parallel-and-concurrent/9781449335939/ch07.html