[prev in list] [next in list] [prev in thread] [next in thread]
List: haskell-cafe
Subject: RE: atomic MVar overwrite (was RE: [Haskell-cafe] How to use QSem?)
From: "Simon Marlow" <simonmar () microsoft ! com>
Date: 2004-06-24 9:08:03
Message-ID: 3429668D0E777A499EE74A7952C382D1020B9C4D () EUR-MSG-01 ! europe ! corp ! microsoft ! com
[Download RAW message or body]
On 23 June 2004 17:46, S. Alexander Jacobson wrote:
> Basically, what I want is a tryReadSampleVar
> function.
>
> Or, if we stick with MVars, I don't want another
> thread to operate between the tryTakeMVar and the
> putMVar. In particular, I don't want another
> thread to believe (mistakenly) that the mvar is
> empty when it is simply being updated.
>
> I suppose I could define a new abstraction where I
> have a second mvar that acts as an exclusive lock
> on the the first MVar. e.g.
>
> data XMVar a = XMVar (MVar ()) MVar a
>
> overWriteXMVar (XMVar lock mvar) val =
> withMVar lock (\_->tryTakeMVar mvar >> putMVar mvar val)
> tryTakeXMVar (XMVar lock mvar) val =
> withMVar lock (\_->tryTakeMVar mvar)
>
> But, I think it would be more sane simply to
> have a tryReadSampleVar somewhere.
If you send me code for tryReadSampleVar, I'll incorporate it.
Unfortunately SampleVar is abstract, so you'll need to take the source
for that library (libraries/base/Control/Concurrent/SampleVar.hs in a
GHC distribution) and modify it to create your own version.
Cheers,
Simon
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic