33
44 Concurrency in Frege comes in 2 flavors.
55 The first is through 'Thread's, which are,
6- unlike in Haskell, @OS@ threads .
6+ unlike in Haskell, _OS threads_ .
77
88 The second possibility is to use a thread pool and an executor service
99 one can submit tasks to. But note that blocking asynchronous tasks,
@@ -14,8 +14,10 @@ module frege.control.Concurrent where
1414
1515import frege.java.util.Concurrent as C
1616
17- --- A thread safe, shared variable, that is either full or empty.
18- abstract data MVar a = MV (BlockingQueue a) where
17+ --- A thread safe, shared variable, that is either full or empty.
18+ --- Technically, this is just a 'BlockingQueue' restricted to length 1.
19+ abstract data MVar a = MV (BlockingQueue a) where
20+
1921 --- create an empty 'MVar'
2022 newEmpty = ArrayBlockingQueue. new 1 >>= return . MV
2123
@@ -31,7 +33,7 @@ abstract data MVar a = MV (BlockingQueue a) where
3133 --- put a value in a 'MVar', returns false if already full.
3234 offer (MV q) a = q. offer a
3335
34- --- get the value from a 'MVar', return 'Nothing' is empty
36+ --- get the value from a 'MVar', return 'Nothing' when empty
3537 poll (MV q) = q. poll
3638
3739-- Haskell compatibility
@@ -42,7 +44,7 @@ tryPutMVar = MVar.offer
4244
4345
4446--- Create and start a new OS 'Thread' that runs an 'IO' action.
45- --- In Frege, there is no difference between 'forkIO' and 'forkOS'
47+ --- In Frege, there is no difference between 'forkIO' and 'frege.control.Concurrent# forkOS' at this time.
4648forkIO :: IO () -> IO Thread
4749forkIO action = do
4850 r <- Runnable. new action
0 commit comments