úÎy ´I      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGH Safe-InferredIStrict function composition.IJKLMNOPIJKLMIJKLM*(c) 2010-2011 Bas van Dijk & Roel van DijkBSD3 (see the file LICENSE)XBas van Dijk <v.dijk.bas@gmail.com> , Roel van Dijk <vandijk.roel@gmail.com> Trustworthy+ 7A lock is in one of two states: "locked" or "unlocked".&Create a lock in the "unlocked" state.$Create a lock in the "locked" state.When the state is "locked" acquire will Q the transaction.When the state is "unlocked" acquire# will change the state to "locked".A non-blocking .When the state is "unlocked"  tryAcquire+ changes the state to "locked" and returns R.When the state is "locked"  tryAcquire( leaves the state unchanged and returns S.release9 changes the state to "unlocked" and returns immediately.CNote that it is an error to release a lock in the "unlocked" state!»A convenience function which first acquires the lock and then performs the computation. When the computation terminates, whether normally or by raising an exception, the lock is released.A non-blocking . tryWithQ is a convenience function which first tries to acquire the lock. If that fails, T£ is returned. If it succeeds, the computation is performed. When the computation terminates, whether normally or by raising an exception, the lock is released and U+ the result of the computation is returned.When the state is "locked", wait will Q the transactionWhen the state is "unlocked" wait returns immediately.wait& does not alter the state of the lock. Note that wait8 is just a convenience function which can be defined as:  wait l =  l V  l 0Determines if the lock is in the "locked" state.yNote that this is only a snapshot of the state. By the time a program reacts on its result it may already be out of date. WX   WX *(c) 2010-2011 Bas van Dijk & Roel van DijkBSD3 (see the file LICENSE)XBas van Dijk <v.dijk.bas@gmail.com> , Roel van Dijk <vandijk.roel@gmail.com>Safe+ -A broadcast is in one of two possible states: "Silent":  ing. to the broadcast will block until a value is ed."Broadcasting x":  ing( to the broadcast will return the value x without blocking. new+ creates a broadcast in the "silent" state. newBroadcasting x* creates a broadcast in the "broadcasting x" state. Listen to a broadcast."If the broadcast is "broadcasting x", listen will return x immediately.If the broadcast is "silent", listen! will block until another thread s a value to the broadcast.+Try to listen to a broadcast; non blocking."If the broadcast is "broadcasting x",  tryListen will return U x immediately.If the broadcast is "silent",  tryListen returns T immediately.GListen to a broadcast if it is available within a given amount of time.Like  (, but with a timeout. A return value of T indicates a timeout occurred.)The timeout is specified in microseconds.UIf the broadcast is "silent" and a timeout of 0 ¼s is specified the function returns T without blocking.<Negative timeouts are treated the same as a timeout of 0 ¼s.Broadcast a value. broadcast b x$ changes the state of the broadcast b to "broadcasting x".3If the broadcast was "silent" all threads that are  ing to the broadcast will be woken.+Broadcast a value before becoming "silent".MThe state of the broadcast is changed to "silent" after all threads that are  ing@ to the broadcast are woken and resume with the signalled value.CThe semantics of signal are equivalent to the following definition:  signal b x = block $  b x >>  b Y?Internally used function that performs the actual broadcast in  and ' then changes to the given final state.&Set a broadcast to the "silent" state. Z[ Y   Z[ Y*(c) 2010-2011 Bas van Dijk & Roel van DijkBSD3 (see the file LICENSE)XBas van Dijk <v.dijk.bas@gmail.com> , Roel van Dijk <vandijk.roel@gmail.com>Safe+ >An event is in one of two possible states: "set" or "cleared".'Create an event in the "cleared" state.#Create an event in the "set" state.Block until the event is .…If the state of the event is already "set" this function will return immediately. Otherwise it will block until another thread calls .b(You can also resume a thread that is waiting for an event by throwing an asynchronous exception.)Block until the event is  or until a timer expires.Like (, but with a timeout. A return value of S indicates a timeout occurred.)The timeout is specified in microseconds.RIf the event is "cleared" and a timeout of 0 ¼s is specified the function returns S without blocking.<Negative timeouts are treated the same as a timeout of 0 ¼s.Returns R( if the state of the event is "set" and S if the state is "cleared".{Notice that this is only a snapshot of the state. By the time a program reacts on its result it may already be out of date.oChanges the state of the event to "set". All threads that where waiting for this event are woken. Threads that ; after the state is changed to "set" will not block at all.kChanges the state to "cleared" after all threads that where waiting for this event are woken. Threads that  after a signal will block until the event is  again.CThe semantics of signal are equivalent to the following definition:  signal e = N $  e >>  e :Changes the state of the event to "cleared". Threads that X after the state is changed to "cleared" will block until the state is changed to "set". \]   \]*(c) 2010-2011 Bas van Dijk & Roel van DijkBSD3 (see the file LICENSE)XBas van Dijk <v.dijk.bas@gmail.com> , Roel van Dijk <vandijk.roel@gmail.com>Safe+ 7A lock is in one of two states: "locked" or "unlocked".&Create a lock in the "unlocked" state.$Create a lock in the "locked" state. Acquires the ,. Blocks if another thread has acquired the .acquire behaves as follows:When the state is "unlocked" acquire changes the state to "locked".When the state is "locked" acquire blocks until a call to !a in another thread wakes the calling thread. Upon awakening it will change the state to "locked"..There are two further important properties of acquire:acquireE is single-wakeup. That is, if there are multiple threads blocked on acquirex and the lock is released, only one thread will be woken up. The runtime guarantees that the woken thread completes its acquire operation.%When multiple threads are blocked on acquireÔ, they are woken up in FIFO order. This is useful for providing fairness properties of abstractions built using locks. (Note that this differs from the Python implementation where the wake-up order is undefined.) A non-blocking .When the state is "unlocked"  tryAcquire+ changes the state to "locked" and returns R.When the state is "locked"  tryAcquire( leaves the state unchanged and returns S.!release9 changes the state to "unlocked" and returns immediately.CNote that it is an error to release a lock in the "unlocked" state!$If there are any threads blocked on  the thread that first called acquire will be woken up."»A convenience function which first acquires the lock and then performs the computation. When the computation terminates, whether normally or by raising an exception, the lock is released. Note that: with = ^ _  !.#A non-blocking ". tryWithQ is a convenience function which first tries to acquire the lock. If that fails, T£ is returned. If it succeeds, the computation is performed. When the computation terminates, whether normally or by raising an exception, the lock is released and U+ the result of the computation is returned.$When the state is "locked", wait blocks until a call to !, in another thread changes it to "unlocked".When the state is "unlocked" wait returns immediately.wait& does not alter the state of the lock. Note that wait5 is just a convenience function we can be defined as:  wait l = block `  l V ! l%0Determines if the lock is in the "locked" state.yNote that this is only a snapshot of the state. By the time a program reacts on its result it may already be out of date. ab !"#$%  !"#$%  !"#$% ab !"#$%*(c) 2010-2011 Bas van Dijk & Roel van DijkBSD3 (see the file LICENSE)XBas van Dijk <v.dijk.bas@gmail.com> , Roel van Dijk <vandijk.roel@gmail.com>Safe+ &The state of an '.T indicates an "unlocked" state.U (tid, n); indicates a "locked" state where the thread identified by tid acquired the lock n times.'ŠA reentrant lock is in one of two states: "locked" or "unlocked". When the lock is in the "locked" state it has two additional properties:Its owner$: the thread that acquired the lock.Its acquired count-: how many times its owner acquired the lock.(0Create a reentrant lock in the "unlocked" state.)lCreate a reentrant lock in the "locked" state (with the current thread as owner and an acquired count of 1).* Acquires the ',. Blocks if another thread has acquired the '.acquire behaves as follows:When the state is "unlocked", acquire[ changes the state to "locked" with the current thread as owner and an acquired count of 1.@When the state is "locked" and the current thread owns the lock acquire$ only increments the acquired count.HWhen the state is "locked" and the current thread does not own the lock acquire blocks> until the owner releases the lock. If the thread that called acquirew is woken upon release of the lock it will take ownership and change the state to "locked" with an acquired count of 1..There are two further important properties of acquire:acquireE is single-wakeup. That is, if there are multiple threads blocked on acquirey, and the lock is released, only one thread will be woken up. The runtime guarantees that the woken thread completes its acquire operation.%When multiple threads are blocked on acquireÓ they are woken up in FIFO order. This is useful for providing fairness properties of abstractions built using locks. (Note that this differs from the Python implementation where the wake-up order is undefined.)+A non-blocking *.When the state is "unlocked"  tryAcquirei changes the state to "locked" (with the current thread as owner and an acquired count of 1) and returns R.When the state is "locked"  tryAcquire( leaves the state unchanged and returns S.,releasew decrements the acquired count. When a lock is released with an acquired count of 1 its state is changed to "unlocked".†Note that it is both an error to release a lock in the "unlocked" state and to release a lock that is not owned by the current thread.$If there are any threads blocked on * the thread that first called acquire will be woken up.-»A convenience function which first acquires the lock and then performs the computation. When the computation terminates, whether normally or by raising an exception, the lock is released. Note that: with = ^ _ * ,..A non-blocking -. tryWithQ is a convenience function which first tries to acquire the lock. If that fails, T£ is returned. If it succeeds, the computation is performed. When the computation terminates, whether normally or by raising an exception, the lock is released and U+ the result of the computation is returned./When the state is "locked" wait blocks until a call to ,, in another thread changes it to "unlocked".When the state is "unlocked" wait returns immediately.wait& does not alter the state of the lock. Note that wait+ is just a convenience function defined as:  wait l = block ` * l V , l0*Determine the state of the reentrant lock.yNote that this is only a snapshot of the state. By the time a program reacts on its result it may already be out of date. &'cd()*+,-./0 &'()*+,-./0 '()*+,-./&0 &'cd()*+,-./0*(c) 2010-2011 Bas van Dijk & Roel van DijkBSD3 (see the file LICENSE)XBas van Dijk <v.dijk.bas@gmail.com> , Roel van Dijk <vandijk.roel@gmail.com>Safe+eInternal state of the 1.1?Multiple-reader, single-writer lock. Is in one of three states:>"Free": Read or write access can be acquired without blocking.K"Read": One or more threads have acquired read access. Blocks write access.s"Write": A single thread has acquired write access. Blocks other threads from acquiring both read and write access.2 Create a new 1T in the "free" state; either read or write access can be acquired without blocking.3 Create a new 1B in the "read" state; only read can be acquired without blocking.4 Create a new 1B in the "write" state; either acquiring read or write will block.5Acquire the read lock.7Blocks if another thread has acquired write access. If  acquireRead; terminates without throwing an exception the state of the 1 will be "read".‹Implementation note: Throws an exception when more than (maxBound :: Int) simultaneous threads acquire the read lock. But that is unlikely.6+Try to acquire the read lock; non blocking.Like 5, but doesn't block. Returns R# if the resulting state is "read", S otherwise.7Release the read lock.aIf the calling thread was the last one to relinquish read access the state will revert to "free".,It is an error to release read access to an 1" which is not in the "read" state.8ÂA convenience function wich first acquires read access and then performs the computation. When the computation terminates, whether normally or by raising an exception, the read lock is released.9A non-blocking 82. First tries to acquire the lock. If that fails, T£ is returned. If it succeeds, the computation is performed. When the computation terminates, whether normally or by raising an exception, the lock is released and U+ the result of the computation is returned.:When the state is "write", waitRead blocks until a call to =/ in another thread changes the state to "free".#When the state is "free" or "read" waitRead returns immediately.waitRead& does not alter the state of the lock. Note that waitRead+ is just a convenience function defined as:  waitRead l = O ` 5 l V 7 l;Acquire the write lock.FBlocks if another thread has acquired either read or write access. If  acquireWrite; terminates without throwing an exception the state of the 1 will be "write".<,Try to acquire the write lock; non blocking.Like ;, but doesn't block. Returns R$ if the resulting state is "write", S otherwise.=Release the write lock.If  releaseWriteC terminates without throwing an exception the state will be "free".-It is an error to release write access to an 1# which is not in the "write" state.>ÄA convenience function wich first acquires write access and then performs the computation. When the computation terminates, whether normally or by raising an exception, the write lock is released.?A non-blocking >2. First tries to acquire the lock. If that fails, T£ is returned. If it succeeds, the computation is performed. When the computation terminates, whether normally or by raising an exception, the lock is released and U+ the result of the computation is returned.@$When the state is "write" or "read"  waitWrite blocks until a call to = or 7/ in another thread changes the state to "free".When the state is "free"  waitWrite returns immediately. waitWrite& does not alter the state of the lock. Note that  waitWrite+ is just a convenience function defined as: waitWrite l = O ` ; l V = lefgh1ijkl23456789:;<=>?@mn123456789:;<=>?@1234578:69;=>@<?ehgf1ijkl23456789:;<=>?@mn&2010 2011 Bas van Dijk & Roel van DijkBSD3 (see the file LICENSE)XBas van Dijk <v.dijk.bas@gmail.com> , Roel van Dijk <vandijk.roel@gmail.com>Safe+EA9Concurrently readable and sequentially writable variable.B Create a new A.C7Execute an action that operates on the contents of the A.fThe action is guaranteed to have a consistent view of the stored value. Any function that attempts to F7 the contents will block until the action is completed.3If another thread is modifying the contents of the AE this function will block until the other thread finishes its action.DLike C but doesn't block. Returns U? the result if read access could be acquired without blocking, T otherwise.EModify the contents of an A.2This function needs exclusive write access to the A . Only one thread can modify an A) at the same time. All others will block.FModify the contents of an A and return an additional value.Like EQ, but allows a value to be returned (²) in addition to the modified value of the A.G%Attempt to modify the contents of an A.Like E, but doesn't block. Returns R$ if the contents could be replaced, S otherwise.H%Attempt to modify the contents of an A and return an additional value.Like F, but doesn't block. Returns U9 the additional value if the contents could be replaced, T otherwise. AoBCDEFGHpABCDEFGHABCDEFGH AoBCDEFGHpq             !"    #$ %&'()*+,-./0123 456789:;<=>?=>@=AB=CDEFGEFH=IJ=IK=LM NOPQ=RS=TU=LV N"N!WXY$#Z[\]3^_concurrent-extra-0.7.0.9Control.Concurrent.STM.LockControl.Concurrent.BroadcastControl.Concurrent.EventControl.Concurrent.LockControl.Concurrent.RLock Control.Concurrent.ReadWriteLockControl.Concurrent.ReadWriteVarUtilsLocknew newAcquiredacquire tryAcquirereleasewithtryWithwaitlocked BroadcastnewBroadcastinglisten tryListen listenTimeout broadcastsignalsilenceEventnewSet waitTimeoutisSetsetclearStateRLockstateRWLocknewAcquiredReadnewAcquiredWrite acquireReadtryAcquireRead releaseReadwithRead tryWithReadwaitRead acquireWritetryAcquireWrite releaseWrite withWrite tryWithWrite waitWriteRWVarmodify_modify tryModify_ tryModify.!ifMpurelyModifyMVar modifyIORefM modifyIORefM_baseGHC.IOmaskmask_ Control.Monadvoid GHC.Conc.Syncretryghc-prim GHC.TypesTrueFalse Data.MaybeNothingJustGHC.Base>>un broadcastThen unBroadcast evBroadcastControl.ApplicativeliftA2Control.Exception.Basebracket_$WriteReadFreereadLock writeLock moduleName $fEqRWLock $fEqRWVar