waiting on multiple MVars

Duncan Coutts duncan@coutts.uklinux.net
Sat, 14 Dec 2002 15:02:49 +0000

Hi all,

I've been experimenting with making an asynchronous IO library. At the
moment it uses Haskell threads but the idea is that it could be
transparently extended to use system AIO.


My question is if there is an effecient way to block / wait on multiple
MVars. takeMVar & readMVar can wait on one MVar. The puspose is to be
able get the reults of a list of AIO operations, in the order in which
they complete.

You could iterate through the list and tryTakeMVar, or spawn a thread to
block on each one and then write into a central MVar or Channel. The
latter is the approach that I am currently using.

the reason you can't simply set them up to all write to a single MVar in
the first place is that it is desirable to be able to have the same AIO
operation be synchronised by multiple readers / clients.

Is there a better way to do this? Or would it need a new MVar /
scheduler primitive?