Simon Marlow wrote:
> The only way I can see to do this is to add a lock field to the MVar. And
> since this lock would look very much like another MVar, you may as well just
> use another MVar to lock it (after all, that adds exactly zero extra
> complication to the system :-).
Absolutely.
> There's still some discussion to be had on what putMVar should do when
> presented with a full MVar. The options are
The logical dual to tryTakeMVar would be
tryPutMVar :: MVar a -> a -> IO Bool
Or even
tryPutMVar :: MVar a -> IO a -> IO (Maybe a)
(the latter only if you can keep the MVar empty while you run the action.)
I have absolutely no need for either of these functions, but would either of
them be implementable without extra expense?