-- Distributed Haskell: multithreading support---- Author : Manuel M T Chakravarty-- Duncan Coutts-- Created: 20 March 2000---- Copyright (c) [2000..2003] Chakravarty & Coutts---- This file is free software; you can redistribute it and/or modify-- it under the terms of the GNU General Public License as published by-- the Free Software Foundation; either version 2 of the License, or-- (at your option) any later version.---- This file is distributed in the hope that it will be useful,-- but WITHOUT ANY WARRANTY; without even the implied warranty of-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-- GNU General Public License for more details.----- DESCRIPTION ------------------------------------------------------------------- Some thread utility functions---- The form of the Fork-Join concurrency operator is taken from-- Arrows for Errors: extending the error monad-- http://www.coutts.uklinux.net/duncan/papers/ssafp02/----- DOCU -------------------------------------------------------------------------- language: Haskell 98 + Concurrency---- Fork-Join concurrency operators-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~---- The type of the operators allows them to be chained like so:-- f &> x <&> y <&> z---- This will fork threads to evaluate x, y and z in parallel and return-- f applied to the results of x, y and z.----- TODO -------------------------------------------------------------------------- * Try implementation not based on throwTomoduleControl.Concurrent.ThreadUtils((<&>),(&>),(&),-- re-exported--forkIO)whereimportPreludehiding(catch)importControl.Concurrent(myThreadId,newEmptyMVar,takeMVar,putMVar,forkIO)importControl.Exception(throwTo,catch)infixl2<&>,&>,&-- fork-join concurrency (EXPORTED)---- * exception safe: when any of the two threads terminates on an exception,-- it is guaranteed that the same exception is raised in the main thread--(<&>)::IO(a->b)->IOa->IObf<&>x=domainId<-myThreadIdxResVar<-newEmptyMVarforkIO$(x>>=putMVarxResVar)`catch`throwTomainId-- propagate exceptionsfRes<-fxRes<-takeMVarxResVarreturn(fResxRes)-- companion opertator to <&> (EXPORTED)--(&>)::(a->b)->(IOa->IOb)f&>x=returnf<&>x-- fork-join concurrency (compat) (EXPORTED)---- * compatibility with previous version of the Ports libary.-- Now a special case of the more general operator.--(&)::IOa->IOb->IO(a,b)m&n=(,)&>m<&>n