úÎÔ]ÏÝ2      !"#$%&'()*+,-./01,`Observable state of holders of lock. The W returns a pair of Ints where the first is number of _ read locks (at least 0) and the second is the number of write locks held (at least 1). The R I returns a map from thread id to the positive number of read locks held. Operation in which error arose  3Exception type thrown or returned by this module. " Impossible"! conditions get the error thrown - and usage problems get the error returned.  Opaque type of the fair RWLock. 23456789:;<= ?Create a new RWLock which starts in a free and unlocked state. WThis is by far the preferred way to acquire a read lock. This uses bracket_ to ensure M acquireRead and releaseRead are called correctly around the passed command. `This ought to ensure releaseRead will not return a (Left error), but if it does then this error  will be thrown. *This can block and be safely interrupted. XThis is by far the preferred way to acquire a write lock. This uses bracket_ to ensure O acquireWrite and releaseWrite are called correctly around the passed command. aThis ought to ensure releaseWrite will not return a (Left error), but if it does then this error  will be thrown. *This can block and be safely interrupted. ^Observe which threads are holding the lock and which threads are waiting (in order). This is ( particularly useful for writing tests. ]checkLocks return a pair of numbers, the first is the count of read locks this thread holds, ` the second is the number of write locks that this thread holds. This may be useful for sanity $ checking complex usage of RWLocks. *This may block and be safely interrupted. _A thread that calls acquireRead must later call releaseRead once for each call to acquireRead. aIf this thread has not previous called acquireRead then releaseRead will do nothing and return a  (Left error). *This can block but cannot be interrupted. >bA thread that calls acquireWrite must later call releaseWrite once for each call to acquireWrite. aIf this thread has not previous called acquireWrite then releaseWrite will do nothing and return  a (Left error). *This can block but cannot be interrupted. ?XAny thread may call acquireRead (even ones holding write locks). This read lock may be N acquired multiple times, requiring an identical number of releaseRead calls. ^All previous calls to acquireWrite by other threads will have succeeded and been released (or 3 interrupted) before this acquireRead will return. `The best way to use acquireRead is to use withRead instead to ensure releaseRead will be called  exactly once. bThis may block and be safely interrupted. If interrupted then the RWLock will be left unchanged. @^Any thread may call acquireWrite (even ones holding read locks, but see below for interrupted ^ behavior). This write lock may be acquired multiple times, requiring an identical number of  releaseWrite calls. ]All previous calls to acquireRead by other threads will have succeeded and been released (or 4 interrupted) before this acquireWrite will return. \The best way to use acquireWrite is to use withWrite instead to ensure releaseWrite will be  called exactly once. _This may block and usually be safely interrupted. If interrupted then the RWLock will be left a unchanged. The exception to being able to interrupted when this blocks is very subtle: if this ` thread holds read locks and calls acquireWrite then it will release those read locks and go to ] the back of the queue to acquire the write lock (it does not get to skip the queue). While ] blocking waiting for the write lock to be available this thread may be interrupted. If not [ interrupted then the write lock will eventually be acquired, followed by re-acquiring the _ original number of read locks. But if acquireWrite is interrupted after releasing read locks c then it MUST restore those read locks on the way out. To do this the internal error handler will  use AE and a special version of acquireRead that skips to the front of the _ queue; when the current lock state is a reader this works instantly but when the current lock b state is a writer this thread will block in an UNINTERRUPTIBLE state until the current writer is _ finished. Once this other writer is finished the error handler will obtain the read locks it 3 needs to allow the error propagation to continue. B         6Sample variables are slightly different from a normal C:  Reading an empty  causes the reader to block.  (same as D on empty C)  Reading a filled  empties it and returns value.  (same as D)  Try reading a filled  returns a Maybe value.  (same as E)  Writing to an empty  fills it with a value, and 8 potentially, wakes up a blocked reader (same as for F on  empty C).  Writing to a filled  overwrites the current value.  (different from F on full C.) MThe readers queue in FIFO order, with the lead reader joining the writers in L a second FIFO queue to access the stored value. Thus writers can jump the H queue of non-leading waiting readers to update the value, but the lead N reader has to wait on all previous writes to finish before taking the value. HThis design choice emphasises that each reader sees the most up-to-date 3 value possible while still guaranteeing progress. GHI: allocates a new MSampleVar in an empty state. No futher # allocation is done when using the . D allocates a new MSampleVar containing the passed value. The value M is not evalated or forced, but stored lazily. No futher allocation is done  when using the . > can block and be interrupted, in which case it does nothing.  If 2 returns then it reports the momentary status the  ?. Using this value without producing unwanted race conditions  is left up to the programmer. If the / is full, forget the value and leave it empty. C Otherwise, do nothing. This avoids any the FIFO queue of blocked !  threads.  B can block and be interrupted, in which case it does nothing. If    returns then it left the  in an empty state. !JWait for a value to become available, then take it and return. The queue  of blocked ! threads is a fair FIFO queue. !C can block and be interrupted, in which case it takes nothing. If  '3readSV returns normally then it has taken a value. "Write a value into the &, overwriting any previous value that  was there. "> can block and be interrupted, in which case it does nothing.  !" !" !"non-portable (concurrency) experimentalhaskell@list.mightyreason.com#A #N is a quantity semaphore, in which the available quantity may be signalled or " waited for in arbitrary amounts. JK4Used to lock access to state of semaphore quantity. L6Used as FIFO queue for waiter, held by head of queue. M1The head of the waiter queue blocks on headWait. NOP?This is the quantity available to be taken from the semaphore. QBIf there is waiter then this is Just the amount being waited for. $$Z allows positive, zero, and negative initial values. The initial value is forced here to  better localize errors. %%R takes a quantity of the semaphore to take and hold while performing the provided  operation. %O ensures the quantity of the sempahore cannot be lost if there are exceptions.  This uses R to ensure ' and ) get called correctly. &&S takes a pure function and an operation. The pure function converts the available a quantity to a pair of the wanted quantity and a returned value. The operation takes the result  of the pure function. &? ensures the quantity of the sempahore cannot be lost if there  are exceptions. This uses R to ensure ( and ) get called correctly. FNote: A long running pure function will block all other access to the # while it is  evaluated. ''[ allow positive, zero, and negative wanted values. Waiters may block, and will be handled  fairly in FIFO order. If '/ returns without interruption then it left the #$ with a remaining quantity that was $ greater than or equal to zero. If '. is interrupted then no quantity is lost. If ' c returns without interruption then it is known that each earlier waiter has definitely either been 2 interrupted or has retured without interruption. (waitWith takes the #H and a pure function that takes the available quantity and computes the b amount wanted and a second value. The value wanted is stricly evaluated but the second value is  returned lazily. ([ allow positive, zero, and negative wanted values. Waiters may block, and will be handled  fairly in FIFO order. If (/ returns without interruption then it left the #$ with a remaining quantity that was $ greater than or equal to zero. If (2 or the provided function are interrupted then no  quantity is lost. If (B returns without interruption then it is known that each previous Y waiter has each definitely either been interrupted or has retured without interruption. FNote: A long running pure function will block all other access to the # while it is  evaluated. ))V allows positive, zero, and negative values, thus this is also way to remove quantity  that skips any threads in the 'wait'/'waitF'3 queue. If the new total is greater than the next b value being waited for (if present) then the first waiter is woken. If there are queued waiters a then the next one will wake after a waiter has proceeded and notice the remaining value; thus a  single )L may result in several waiters obtaining values. Waking waiting threads is  asynchronous. )Y may block, but it cannot be interrupted, which allows it to dependably restore value to  the #. All ), *, +1, and the head waiter may momentarily block in a  fair FIFO manner. *?Instead of providing a fixed change to the available quantity, * applies a provided X pure function to the available quantity to compute the change and a second value. The e requested change is stricly evaluated but the second value is returned lazily. If the new total is c greater than the next value being waited for then the first waiter is woken. If there are queued b waiters then the next one will wake after a waiter has proceeded and notice the remaining value;  thus a single *I may result in several waiters obtaining values. Waking waiting threads  is asynchronous. *X may block, and it can be safely interrupted. If the provided function throws an error & or is interrupted then it leaves the # unchanged. All ), *, +, and > the head waiter may momentarily block in a fair FIFO manner. FNote: A long running pure function will block all other access to the # while it is  evaluated. ++ skips the queue of any blocked ' and ( threads, but may momentarily  block on ), *, other +2, and the head waiter. This returns the amount of c value available to be taken. Using this value without producing unwanted race conditions is left  up to the programmer. + is an optimized form of " signalF m (x -> (0,x))".  A version of + that joins the FIFO queue of ' and ( can be acheived by  " waitF m (x -> (0,x))" #$%&'()*+ #$%')&(*+ #$%&'()*+non-portable (concurrency) experimentalhaskell@list.mightyreason.com ,A ,S is a semaphore in which the available quantity can be added and removed in single E units, and which can start with positive, zero, or negative value. STCUsed to lock access to state of semaphore quantity. Never updated. UFUsed as FIFO queue for waiter, held by head of queue. Never updated. V@The head of the waiter queue blocks on headWait. Never updated. --Z allows positive, zero, and negative initial values. The initial value is forced here to  better localize errors. MThe only way to acheive a negative value with MSem is to start negative with -. Once the quantity ..P takes a unit of value from the semaphore to hold while performing the provided  operation. .O ensures the quantity of the sempahore cannot be lost if there are exceptions. . uses W to ensure / and 0 get called correctly. //Z will take one unit of value from the sempahore, but will block if the quantity available  is not positive. If // returns without interruption then it left the ,$ with a remaining quantity that was $ greater than or equal to zero. If /. is interrupted then no quantity is lost. If / c returns without interruption then it is known that each earlier waiter has definitely either been 2 interrupted or has retured without interruption. 00! adds one unit to the sempahore. 0Y may block, but it cannot be interrupted, which allows it to dependably restore value to  the ,. All 0, 1;, and the head waiter may momentarily block in a fair FIFO  manner. 11 skips the queue of any blocked /' threads, but may momentarily block on  0, other 1E, and the head waiter. This returns the amount of value available to Z be taken. Using this value without producing unwanted race conditions is left up to the  programmer.  Note that Control.Concurrent.MSemN> offers a more powerful API for making decisions based on the  available amount. ,-./01,-./01,-./01X      !"#$%&'()*+,-./(*,.0123456789:;<=>?@AB?CD?CE?CF?CG HI'JKLMMNO?PQ/JKL?PRSSafeSemaphore-0.7.0Control.Concurrent.FairRWLockControl.Concurrent.MSampleVarControl.Concurrent.MSemNControl.Concurrent.MSemFRWWRFRWLockExceptionKindRWLock'releaseReadRWLock'acquireReadRWLock'releaseWriteRWLock'acquireWriteRWLockExceptionRWLockLockKind WriterKindunWK ReaderKindunRKTSetTMapnewwithRead withWritepeekLock checkLock releaseRead releaseWrite acquireRead acquireWrite MSampleVar newEmptySVnewSV isEmptySVemptySVreadSVwriteSVMSemNwithwithFwaitwaitFsignalsignalF peekAvailMSemRWLLockUserWriterwriterID writerCount readerCountqueueReaders readerCountsqueueRFreeLockLockQ releaseRead' releaseWrite'acquireReadPrioritybaseGHC.IOuninterruptibleMask_impGHC.MVarMVartakeMVar tryTakeMVarputMVar readQueue lockedStoremSem queueWaitheadWaitMSavail headWantsControl.Exception.Basebracketbracket_