[prev in list] [next in list] [prev in thread] [next in thread]
List: haskell-cafe
Subject: Re: [Haskell-cafe] Shared/Exclusive Locks
From: Robert Dockins <robdockins () fastmail ! fm>
Date: 2005-12-28 19:08:04
Message-ID: 913953D1-BBD0-429E-A38F-BC3EDC3D48EB () fastmail ! fm
[Download RAW message or body]
On Dec 28, 2005, at 1:38 PM, Tomasz Zielonka wrote:
> On Wed, Dec 28, 2005 at 05:28:28PM +0000, Chris Kuklewicz wrote:
>> But STM, wrapped in small pieces, makes for interesting IO commands
>> (untested):
>
>> waitForZero :: (Num a, Ord a) => (TVar a) -> IO ()
>> waitForZero tv = atomically $ do
>> v <- readTVar tv
>> when (v>0) retry
>
> This function is rather useless in IO - you will get race conditions.
> That's what you get for leaving the STM wonderland ;-)
Actually, I think it works in the particular instance given of
constructing read-write locks because the call to waitForZero is
guarded by a mutex. But it would certainly be easy to introduce a
race condition using constructs like this. Given the alternatives
{use STM fully, use STM some, don't use STM}, I would have a hard
time justifying the "use STM some" alternative (at least for new
programs). If you are OK with introducing a dependency on STM, why
not go whole hog?
Rob Dockins
Speak softly and drive a Sherman tank.
Laugh hard; it's a long way to the bank.
-- TMBG
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic