#3159: QSem fails with negative quantities
---------------------------------+------------------------------------------
Reporter: NeilMitchell | Owner:
Type: bug | Status: closed
Priority: normal | Milestone:
Component: libraries/base | Version: 6.10.2
Severity: major | Resolution: fixed
Keywords: | Difficulty: Unknown
Testcase: | Os: Unknown/Multiple
Architecture: Unknown/Multiple |
---------------------------------+------------------------------------------
Changes (by igloo):
* status: new => closed
* difficulty: => Unknown
* resolution: => fixed
Comment:
"Simple quantity semaphores" can't have negative amounts available; the
bug here is that `newQSem` doesn't check that it has been given a non-
negative argument; fixed for both `QSem` and `QSemN` by:
{{{
Fri Apr 10 17:40:13 BST 2009 Ian Lynagh <[email protected]>
* Fix QSem and QSemN: Initial amount must be non-negative
}}}
You can write your program with `QSemN`:
{{{
import Data.IORef
import Control.Concurrent
main = do
sem <- newQSemN 0
r <- newIORef 0
let incRef = atomicModifyIORef r (\a -> (a+1,a))
sequence_ $ replicate 100 $ forkIO $ incRef >> signalQSemN sem 1
waitQSemN sem 100
v <- readIORef r
print v
}}}
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3159#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs