atom feed1 message in org.haskell.glasgow-haskell-userswaiting on multiple MVars
FromSent OnAttachments
Duncan CouttsDec 14, 2002 7:02 am 
Subject:waiting on multiple MVars
From:Duncan Coutts (
Date:Dec 14, 2002 7:02:49 am

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?