[Haskell] Wait for *either* MVar to be set

Simon Peyton-Jones simonpj at microsoft.com
Thu Nov 27 03:48:28 EST 2008


| However, preemptive multitasking operating systems offer support for waiting for multiple
| "MVars", until *either* one of them returns (or timeouts).

The standard way to do this is to spawn a thread for each MVar you are waiting for; the thread blocks on the MVar and, when it unblocks it fills a third MVar with the outcome.  The original thread waits on this single MVar.  See Section 5 of http://research.microsoft.com/users/simonpj/papers/concurrent-haskell.ps.gz

Alternatively STM supports such multiple waiting directly
http://research.microsoft.com/%7Esimonpj/papers/stm/index.htm#composble

Simon

| -----Original Message-----
| From: haskell-bounces at haskell.org [mailto:haskell-bounces at haskell.org] On Behalf Of Peter
| Verswyvelen
| Sent: 26 November 2008 18:05
| To: haskell at haskell.org
| Subject: [Haskell] Wait for *either* MVar to be set
|
| Maybe this is not the correct mailing list to ask this question, but as a similar question was
| asked seemingly unanswered by Duncan Coutts in 2002
| (http://markmail.org/message/kftpnulks7mbz2ij), and as this most likely has to do with the GHC
| runtime, I might have more luck to get an answer here... Sorry for the spam if this is
| inappropriate; please say so and I will resubscribe to the Haskell Cafe mailing list, not
| polluting this main list anymore...
|
| So here's my question.
|
| GHC provides MVar for nice lightweight concurrency synchronization.
|
| However, preemptive multitasking operating systems offer support for waiting for multiple
| "MVars", until *either* one of them returns (or timeouts).
|
| I see no way of achieving this with GHC's MVar, unless using Conal Elliott's unamb package on
| Hackage that emulates this by spawning and killing two threads (which might be an expensive
| operation, I'm not sure)
|
| Am I wrong in this? If so, is this something that might be considered as a future enhancement
| in the GHC libraries and runtime?
|
| Thanks very much,
| Peter Verswyvelen
| CTO - Anygma
|
|
|
|
| _______________________________________________
| Haskell mailing list
| Haskell at haskell.org
| http://www.haskell.org/mailman/listinfo/haskell



More information about the Haskell mailing list