[commit: ghc] master: Fixed "Memory Model" example. (c4b8e71)

git at git.haskell.org git at git.haskell.org
Mon Jul 16 23:56:37 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/c4b8e719effe9b420b1c5cec0194134a44b26823/ghc

>---------------------------------------------------------------

commit c4b8e719effe9b420b1c5cec0194134a44b26823
Author: Francesco Ariis <fa-ml at ariis.it>
Date:   Mon Jul 16 19:56:03 2018 -0400

    Fixed "Memory Model" example.
    
    removed whitespace and added relevant imports to the
    "Memory Model" example (haddock documentation).
    
    Reviewers: hvr, bgamari
    
    Reviewed By: bgamari
    
    Subscribers: RyanGlScott, rwbarton, thomie, carter
    
    Differential Revision: https://phabricator.haskell.org/D4966


>---------------------------------------------------------------

c4b8e719effe9b420b1c5cec0194134a44b26823
 libraries/base/Data/IORef.hs | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/libraries/base/Data/IORef.hs b/libraries/base/Data/IORef.hs
index 6f07a09..4476926 100644
--- a/libraries/base/Data/IORef.hs
+++ b/libraries/base/Data/IORef.hs
@@ -111,19 +111,23 @@ atomicWriteIORef ref a = do
   processor architecture.  For example, on x86, loads can move ahead
   of stores, so in the following example:
 
->  maybePrint :: IORef Bool -> IORef Bool -> IO ()
->  maybePrint myRef yourRef = do
->    writeIORef myRef True
->    yourVal <- readIORef yourRef
->    unless yourVal $ putStrLn "critical section"
->
->  main :: IO ()
->  main = do
->    r1 <- newIORef False
->    r2 <- newIORef False
->    forkIO $ maybePrint r1 r2
->    forkIO $ maybePrint r2 r1
->    threadDelay 1000000
+  > import Data.IORef
+  > import Control.Monad (unless)
+  > import Control.Concurrent (forkIO, threadDelay)
+  >
+  > maybePrint :: IORef Bool -> IORef Bool -> IO ()
+  > maybePrint myRef yourRef = do
+  >   writeIORef myRef True
+  >   yourVal <- readIORef yourRef
+  >   unless yourVal $ putStrLn "critical section"
+  >
+  > main :: IO ()
+  > main = do
+  >   r1 <- newIORef False
+  >   r2 <- newIORef False
+  >   forkIO $ maybePrint r1 r2
+  >   forkIO $ maybePrint r2 r1
+  >   threadDelay 1000000
 
   it is possible that the string @"critical section"@ is printed
   twice, even though there is no interleaving of the operations of the



More information about the ghc-commits mailing list