Bug in 4.08.1 hslib/concurrent/semaphores....

Simon Peyton-Jones simonpj at microsoft.com
Thu Jan 11 04:29:24 EST 2001


An excellent point.  Thank you.  Will be fixed in 4.08.2

Simon

| -----Original Message-----
| From: Marcus Shawcroft [mailto:marcus.shawcroft at ericsson.com]
| Sent: 10 January 2001 14:45
| To: glasgow-haskell-bugs at haskell.org
| Subject: Bug in 4.08.1 hslib/concurrent/semaphores....
| 
| 
| Hi,
| 
| I'm using 4.08.1 on linux.
| 
| I think that `waitQSemN' provided with the concurrent library 
| is broken,
| the following code should drop straight through, in practice waitQSemN
| blocks.....
| 
| 
| > module Main (main) where
| 
| > import Concurrent
| 
| > main :: IO ()
| > main
| >   = do sem <- newQSemN 1
| >            waitQSemN sem 1
| 
| 
| Below is my fix:
| 
| Index: QSemN.lhs
| ===================================================================
| RCS file: /export/home1/CVSROOT/fptools/hslibs/concurrent/QSemN.lhs,v
| retrieving revision 1.1.1.1
| diff -c -r1.1.1.1 QSemN.lhs
| *** QSemN.lhs 2000/09/18 09:44:34 1.1.1.1
| --- QSemN.lhs 2001/01/10 14:30:44
| ***************
| *** 39,45 ****
|   waitQSemN :: QSemN -> Int -> IO ()
|   waitQSemN (QSemN sem) sz = do
|     (avail,blocked) <- takeMVar sem   -- gain ex. access
| !   if (avail - sz) > 0 then
|          -- discharging 'sz' still leaves the semaphore
|          -- in an 'unblocked' state.
|        putMVar sem (avail-sz,[])
| --- 39,45 ----
|   waitQSemN :: QSemN -> Int -> IO ()
|   waitQSemN (QSemN sem) sz = do
|     (avail,blocked) <- takeMVar sem   -- gain ex. access
| !   if (avail - sz) >= 0 then
|          -- discharging 'sz' still leaves the semaphore
|          -- in an 'unblocked' state.
|        putMVar sem (avail-sz,[])
| 
| 
| Cheers
| /Marcus
| 
| --
| Marcus Shawcroft
| Ericsson Mobile Applications
| 
| 
| 




More information about the Glasgow-haskell-bugs mailing list