No atomic read on MVar?

Arnar Birgisson arnarbi at gmail.com
Tue Nov 4 04:51:09 EST 2008


On Mon, Nov 3, 2008 at 23:51, David Menendez <dave at zednenem.com> wrote:
> On Mon, Nov 3, 2008 at 6:29 AM, Philip K.F. Hölzenspies
> <p.k.f.holzenspies at utwente.nl> wrote:
>>
>> I have now implemented my variable as a pair of MVars, one of which serves as
>> a lock on the other. Both for performance reasons and for deadlock analysis,
>> I would really like an atomic read on MVars, though. Does it exist? If not,
>> why not?
>
> Have you considered using STM? All the operations on TMVars are atomic.

I will second this. At the very least, if you only need atomic
read/write operations you can use TMVars and make aliases that compose
with atomically:

takeMVar = atomically . takeTMVar
putMVar = atomically . putTMVar

etc.

cheers,
Arnar


More information about the Glasgow-haskell-users mailing list