o)      !"#$%&'(,Portability : concurrency, unsafeIntereaveIO!John Launchbury <john@galois.com>)*+,CA group can be closed, in which case it is empty and cannot accept C new inhabitants, or open, in which case it contains any number of 3 threads and groups and may have additional threads/groups registered. -. A thread / keeps tracks of its inhabitants, which may be  threads or other s. The  monad is simply the / monad augmented with an , environment that tracks the current thread . This permits us ? to keep track of forked threads and kill them en mass when an  ancestor is killed. The  monad is an instance of 0, so  arbitrary /5 actions may be embedded in it; however, the user is D advised that any action may be summarily killed, and thus it is of B extra importance that appropriate bracketing functions are used. 12@Creates a new thread group and registers the current environment's B thread group in it. If the current group is closed, immediately - terminates execution of the current thread. Explicitly sets the current  environment for a  monad. ,Kill all threads which are descendants of a  and closes the D group, disallowing new threads or groups to be added to the group.  Doesn'.t do anything if the group is already closed. Blocks until the  w is finished executing. Runs a 1 operation inside a new thread group that has no C parent, and blocks until all subthreads of the operation are done  executing. If countingThreads is True, it then prints some > debugging information about the threads run (XXX: this seems  suboptimal.) #Creates a new, empty thread group. 3Registers a thread/ group entry tid in a , terminating the 2 current thread (suicide) if the group is closed. 4Recursively kills a thread/'group entry. Does not do anything the  entry is a closed group. 56789:;<EThe thread-registry environment is a hierarchical structure of local  thread neighborhoods. Portability : concurrency!John Launchbury <john@galois.com> BA monad for many-valued concurrency, external actions and managed # resources. An expression of type Orc a may perform many actions ! and return many results of type a. The = instance does  not obey the Right-Zero law ( p >> stop /= stop). >? BFinish the local thread of operations, so that anything sequenced > afterwards is not executed. It satisfies the following law:  stop >>= k == stop @6Parallel choice operator that performs the actions of p and q C and returns their results as they become available. Also written  as  |4. There is no left-right bias: the ordering between p and  q is unspecified. @) satisfies the following laws (identity, D commutativity, associativity and left-distributivity across bind):  p <|> stop == p  p <|> q == q <|> p $ p <|> (q <|> r) == (p <|> q) <|> r 0 ((p <|> q) >>= k) == ((p >>= k) <|> (q >>= k)) >Runs an Orc computation, discarding the (many) results of the  computation. See collect+ on a mechanism for collecting the results F of a computation into a list, which may then be passed to another IO  thread. ?Biased choice operator (pronounced and-then) that performs the ) action (and returns all the results) of p first, and then once done  performs the action of q. "Immediately fires up a thread for p, and then returns a handle to 7 the first result of that thread which is also of type Orc a. An  invocation to  - is non-blocking, while an invocation of the  resulting handle is blocking.   satisfies the following  laws:  Par-eagerly:  ! eagerly p >>= (\x -> k x <|> h)  == (eagerly p >>= k) <|> h Eagerly-swap:   do y <- eagerly p  x <- eagerly q  k x y  == do x <- eagerly q  y <- eagerly p  k x y  Eagerly-IO: 5 eagerly (liftIO m) >> p == (liftIO m >> stop) <|> p An alternate mechanism for  , it fires up a thread for p D and returns a lazy thunk that contains the single (trimmed) result ; of the computation. Be careful to use this function with public E when these lazy values need to be fully evaluated before proceeding A further. For example, the following code succeeds immediately:   do x <- val p  return x Whereas this code waits until p! has generated one result before  returning:  do x <- val p  publish p ABCDEFG=HIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~0   Portability : concurrency!John Launchbury <john@galois.com>Alternate phrasing of  return ()!, which can be placed at the end ? of an Orc computation to signal that it has no more values to  produce. ECut executes an orc expression, waits for the first result, and then = suppresses the rest, including killing any threads involved  in computing the remainder. Executes the computation p and done. Once done returns its E first result, kill both computations and returns that result. This  discards the results of p. %Immediately executes the computation p, but if it hasn' t returned  a result in t" seconds, execute the computation q and return B whichever computations returns a result first (killing the other  thread). Executes a computation p, but if it hasn't returned a result in  n seconds return a instead (killing the p computation). Executes the computation p but suppresses its results.  Lifts a list into an Orc monad. $Repeatedly executes the computation p and returns its  results.  works best when p is single-valued:  if p< is multivalued Orc will spawn a repeating thread for every 9 result returned, resulting in an exponential blow-up of  threads (XXX: I don'%t think this was actually intended.) Runs a computation p' and writes its results to the channel ch. Takes the first result of p, the first result of  q, and applies them to f. The computations for p and q are  run in parallel. Runs the computation p( and returns its first result, but doesn't  return before w seconds have elapsed.  Runs a list of Orc computations ps in parallel until they produce > their first result, and returns a list of all these results. :Wait for a period of w seconds, then continue processing. DRuns an Orc computation, eagerly printing out the results of an Orc  computation line-by-line. 2Prompts the user for a string. Concurrency-safe. CWrites a string and newline to standard output. Concurrency-safe. <Analogous to the list scan function, but the order in which > the combining function is applied to the results produced by  p is nondeterministic.  A variant of  1, pronounced or-else, which performs and returns  the results of p , and if p( produced no answers go on and performa  dn return the results of q. For each value produced by p , return a Left a. Once p has  finished, return a  Right Int" containing the number of results  produced. !.Collects all of the values of the computation p and delivers them  as a list when p is completed. "List-like functions Runs the computation p and returns the first n results. #Drops the first n results of the computation p , and then " returns the rest of the results. $%Zips the results of two computations p and q . When one ' computation finishes, kill the other. %Runs the computation p*, and repeatedly puts its results (tagged  with  into the vals m. Puts  if there are no ) results left. Stops executing when the end MVar is filled. &The rough inverse of %#, repeatedly reads values from the  vals m until j values have been read or the vals MVar is  exhausted (a / is passed). When there are no more values to  be returned, fills the end MVar. 'Like &#, repeatedly reads values from the pvals and qvals  m+, returning tuples of the values until one m is exhausted. 9 When there are no more values to be returned, fills the end MVar. (6Publish is a hyperstrict form of return. It is useful ' for combining results from multiple   computations, providing  a synchronization point.  !"#$%&'( !"#$%&'( !"#$%&'(Portability : concurrency!John Launchbury <john@galois.com>BCDEFG=HIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~0  !"#$%&'(      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHCIJCIKCILCIMCINCIOCPQCPRCPSCPTCPUCPVCPWCPXCPYCPZCP[CP\CP]CP^CP_CP`CPaCPaCPbCPcCPdCPeCPfCPgCPhCPiCPiCjkClmClnCloClpClqClrClsCltCuvCwxCDyCDzCD{CD|CD}CD~CDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCICI56CC orc-1.2.1.1Control.Concurrent.Hierarchical Orc.MonadOrc.CombinatorsOrcGroupHIOnewGrouplocalclosefinishedrunHIO newPrimGroupstoprunOrc<+>eagerlyvalsignalcut onlyUntilbutAftertimeoutsilentliftList repeatingrunChansync notBeforesyncListdelayprintOrcprompt putStrLinescancountcollecttakeOrcdropOrczipOrcsandboxechozipppublishEntryThread InhabitantsOpenClosedghc-prim GHC.TypesIOtransformers-0.2.2.0Control.Monad.IO.ClassMonadIOinGroupregisterkill increment decrementisZerocountingThreads threadCountincrementThreadCountprintThreadReport $fMonadIOHIObase Control.Monad MonadPlus#parsaveOnceGHC.Basefail>>=>>returnMonadFunctorControl.Applicative ApplicativeoptionalliftA3liftA2liftA<**><**><*>puremanysome<|>empty AlternativegetConstConst unwrapMonad WrapMonad WrappedMonad unwrapArrow WrapArrow WrappedArrow getZipListZipListControl.Concurrent.ChanChan GHC.Conc.SyncalwaysalwaysSucceedscatchSTMorElseretryThreadIdSTMTVar Data.Functor<$>GHC.MVarMVarmfilterapliftM5liftM4liftM3liftM2liftMunlesswhen replicateM_ replicateMfoldM_foldM zipWithM_zipWithM mapAndUnzipMjoinvoidforever<=<>=>msumforM_forMfilterMguardmapM_mapM sequence_sequence=<<mplusmzero<$fmapmonadIO-0.10.1.1Control.Concurrent.STM.MonadIOisEmptyTMVarSTMtryPutTMVarSTMtryTakeTMVarSTM swapTMVarSTM readTMVarSTM putTMVarSTM takeTMVarSTMnewEmptyTMVarSTM newTMVarSTM modifyTMVar_ modifyTMVar isEmptyTMVar tryPutTMVar tryTakeTMVar swapTMVar readTMVarputTMVar takeTMVar newEmptyTMVarnewTMVar writeTVarSTM readTVarSTM newTVarSTM modifyTVar_ modifyTVar registerDelay writeTVarreadTVarnewTVar atomicallyControl.Concurrent.MonadIO threadDelayyieldthrowTo killThread myThreadIdforkIOwriteList2ChangetChanContents isEmptyChan unGetChandupChanreadChan writeChannewChan isEmptyMVar tryPutMVar tryTakeMVarswapMVarreadMVarputMVartakeMVarnewMVar newEmptyMVarforkHasFork stm-2.2.0.1Control.Concurrent.STM.TMVarTMVarControl.Monad.STMcheckliftIO Data.MaybeJustNothing