Package IO/THREADS-EXCEPTIONS
Types
SynchronousThreadException TYPE · src
Exceptions that a thread raises whenever it encounters a threading related problem. Unlike ThreadingException, these are actual exceptions.
ThreadingException TYPE · src
(InterruptCurrentThread String)
Thread exception sent asynchronously between threads. This type isn't really an exception, it's more of a message.
UnmaskFinallyMode TYPE · src
RunningStopped
When a thread unmasks and calls a cleanup operation, the thread is either: * Still running, and will cleanup and continue * Received a stop while it was masked, and will cleanup and then terminate itself.
Values
(DYNAMIC-IS-THREADING-EXCEPTION? DYN) FUNCTION · src
Dynamic → BooleanReturns true if the dynamic val is a threading exception or an IoError containing a ThreadingException.
(IS-THREADING-EXCEPTION IO-ERR) FUNCTION · src
IoError → BooleanReturn True if IO-ERR contains a threading exception.
Package IO/EXCEPTIONS
Classes
Exceptions CLASS · src
Monad :M ⇒ Exceptions :MA Monad that can raise and handle exceptions. IMPORTANT: Any Exceptions must catch and wrap all unhandled errors inside a wrap-io call.
Methods:RAISE :: (RuntimeRepr :E) (Signalable :E) ⇒ :E → :M :A
Raise an exception.RAISE-DYNAMIC :: Dynamic → :M :A
Raise an exception wrapped in a Dynamic. Mainly useful to hand-off eexceptions between IO instances.RERAISE :: :M :A * (Void → :M :B) → :M :A
Run an operation, run a catch operation if the first operation raised, then re-raise the exception. If the catch operation raises, that exception will be emitted instead of the original exception.HANDLE :: RuntimeRepr :E ⇒ :M :A * (:E → :M :A) → :M :A
Run an operation, immediately handling if it raised an exception that matches :e.HANDLE-ALL :: :M :A * (Void → :M :A) → :M :A
Run an operation, immediately handling any exceptions raised.TRY-DYNAMIC :: :M :A → :M (Result Dynamic :A)
Bring any unhandled exceptions into a Result wrapped in Dynamic.
Instances
Exceptions IO(Exceptions :IO) (MonadIo :IO) ⇒ Exceptions (STM :IO)Exceptions :M ⇒ Exceptions (EnvT :E :M)Exceptions :M ⇒ Exceptions (StateT :S :M)
Values
(RAISE-RESULT IO-RES) FUNCTION · src
∀ :M :E :A. (Exceptions :M) (RuntimeRepr :E) (Signalable :E) ⇒ :M (Result :E :A) → :M :ARaise any (Err :e) into :m. Useful if (Err :e) represents any unhandleable, fatal exception to the program.
(RAISE-RESULT-DYNAMIC OP) FUNCTION · src
∀ :M :A. Exceptions :M ⇒ :M (Result Dynamic :A) → :M :A(TRY OP) FUNCTION · src
∀ :M :A :E. (Exceptions :M) (RuntimeRepr :E) ⇒ :M :A → :M (Result :E :A)Bring any unhandled exceptions of type :e up into a Result. Continues to carry any unhandeld exceptions not of type :e.
(TRY-ALL OP) FUNCTION · src
∀ :M :A. Exceptions :M ⇒ :M :A → :M (Optional :A)Bring the result of OP up into an Optional. Returns None if OP raised any exceptions.
(TRY-RESULT OP) FUNCTION · src
∀ :M :A :E. (Exceptions :M) (RuntimeRepr :E) (Signalable :E) ⇒ :M :A → :M (Result :E :A)(WRAP-ERROR_ THUNK) FUNCTION · src
∀ :A :M. Exceptions :M ⇒ (Void → :A) → :M :ARun thunk, catching any unhandled Lisp/Coalton errors and raising them as exceptions.
Macros
DO-HANDLE-ALL (OP &BODY BODY) MACRO
Convenience macro for handle-all. Example: (do-handle-all add-three-ints (modify (Cons 2)) (pure 10)) ===> (handle-all add-three-ints (fn () (do (modify (cons 2)) (pure 10))))
DO-HANDLE (OP (ERR-SYM) &BODY BODY) MACRO
Convenience macro for handle.
WRAP-ERROR (&BODY BODY) MACRO
Run BODY, catching any unhandled Lisp/Coalton errors and raising them as exceptions.
DO-RERAISE (OP &BODY BODY) MACRO
Convenience macro for reraise.
Package IO/MONAD-IO
Classes
BaseIo CLASS · src
MonadIo :M ⇒ BaseIo :MA 'base' IO implementation, which can be run to execute some (potentially side-effectful) operation.
Methods:RUN! :: :M :A → :A
Run a (potentially) side-effectful operation. Throws any unhandled exceptions.RUN-HANDLED! :: :M :A → Result Dynamic :A
Run a (potentially) side-effectful operation. Returns any unhandled exceptions as an (Err e).
LiftIo CLASS · src
(Monad :M) (BaseIo :I) ⇒ LiftIo :I :MMethods:
LIFT-IO :: BaseIo :I ⇒ :I :A → :M :A
Instances
MonadIo CLASS · src
Monad :M ⇒ MonadIo :MMethods:
WRAP-IO_ :: (Void → :A) → :M :A
Wrap a (potentially) side-effectful function in the monad.
Instances
UnliftIo CLASS · src
(MonadIo :M) (LiftIo :I :M) ⇒ UnliftIo :M :IMethods:
WITH-RUN-IN-IO :: ((:M :A → :I :A) → :I :B) → :M :B
Values
(FOREACH-IO COLL A->MB) FUNCTION · src
∀ :IO :I :A :R :B :M. (UnliftIo :R :IO) (LiftTo :R :M) (IntoIterator :I :A) ⇒ :I * (Cell :A → :R :B) → :M UnitEfficiently perform a monadic operation for each element of an iterator. The next element of the iterator is passed into the operation via a cell. If your effect can be run in simple-io/IO, the version in that package will be faster!
(MAP-INTO-IO ITR A->RB) FUNCTION · src
∀ :IO :I :A :R :B :M. (UnliftIo :R :IO) (LiftTo :R :M) (IntoIterator :I :A) ⇒ :I * (:A → :R :B) → :M (List :B)Efficiently perform a monadic operation for each element of an iterator and return the results. If you're having inference issues, try map-into-io_
(TIMES-IO N IO-OP) FUNCTION · src
∀ :IO :R :B :M. (UnliftIo :R :IO) (LiftTo :R :M) ⇒ UFix * :R :B → :M UnitEfficiently perform an IO operation N times. If the effect can be run in simple-io/IO, the version in that package will be faster!
Macros
DO-TIMES-IO (N &BODY BODY) MACRO
Efficiently perform an IO operation N times. If the effect can be run in simple-io/IO, the version in that package will be faster!
DERIVE-LIFT-IO (MONAD-PARAM MONADT-FORM) MACRO
Automatically derive an instance of LiftIo for a monad transformer. Example: (derive-lift-io :m (e:EnvT :e :m))
DO-FOREACH-IO ((VAR-SYM INTO-ITR) &BODY BODY) MACRO
Efficiently perform a monadic operation for each element of an iterator. VAR-SYM is bound to the value of the element in the iterator. If your effect can be run in simple-io/IO, the version in that package will be faster!
DERIVE-MONAD-IO (MONAD-PARAM MONADT-FORM) MACRO
Automatically derive an instance of MonadIo for a monad transformer. Example: (derive-monad-io :m (st:StateT :s :m))
RUN-AS! (M-TYPE M-OP) MACRO
Run M-OP using the concrete RunIo M-TYPE. Useful for situations where you want to create a generic MonadIo operation and immediately run it, so the compiler can't infer the type of the actual monad you want to use. Example: (run-as! (IO Unit) (pure Unit)) NOTE: Unfortunately, there seems to be a type inference bug that requires putting in the full type of M-OP, not just (IO :a).
WRAP-IO (&BODY BODY) MACRO
Wrap the execution of BODY in the IO monad. Supports any MonadIo instance. Example: (wrap-io (lisp (-> :a) (str) (cl:print str))
DO-MAP-INTO-IO ((VAR LST) &BODY BODY) MACRO
Package IO/SIMPLE-IO
Values
(FOREACH-IO_ COLL A->MB) FUNCTION · src
∀ :I :A :B :M. (LiftIo IO :M) (IntoIterator :I :A) ⇒ :I * (Cell :A → IO :B) → :M UnitEfficiently perform a monadic operation for each element of an iterator. More efficient than foreach-io, if your effect can run in IO. The next element of the iterator is passed into the operation via a cell.
(HANDLE-ALL-IO IO-OP HANDLE-OP) FUNCTION · src
∀ :A. IO :A * (Void → IO :A) → IO :ARun IO-OP, and run HANDLE-OP to handle exceptions of any type thrown by IO-OP.
(HANDLE-IO IO-OP HANDLE-OP) FUNCTION · src
∀ :A :E. RuntimeRepr :E ⇒ IO :A * (:E → IO :A) → IO :A(MAP-INTO-IO_ ITR A->MB) FUNCTION · src
∀ :I :A :B :M. (LiftIo IO :M) (IntoIterator :I :A) ⇒ :I * (:A → IO :B) → :M (List :B)Efficiently perform a monadic operation for each element of an iterator and return the results. More efficient than map-into-io, if you can run your effect in a BaseIo.
(RAISE-DYNAMIC-IO DYN) FUNCTION · src
∀ :A. Dynamic → IO :A(RAISE-IO E) FUNCTION · src
∀ :E :A. (RuntimeRepr :E) (Signalable :E) ⇒ :E → IO :A(RAISE-IO_) FUNCTION · src
∀ :E. (RuntimeRepr :E) (Signalable :E) ⇒ :E → IO Unit(RERAISE-IO OP CATCH-OP) FUNCTION · src
∀ :A :B. IO :A * (Void → IO :B) → IO :A(RUN-IO! IO-OP) FUNCTION · src
∀ :A. IO :A → :ATop-level run-io! that raises any unhandled exceptions. Also sets the current thread as the global thread for structured concurrency, and exits any child threads on exit.
(TIMES-IO_ N IO-OP) FUNCTION · src
∀ :A :M. LiftIo IO :M ⇒ UFix * IO :A → :M UnitEfficiently perform an IO operation N times.
(TRY-DYNAMIC-IO IO-OP) FUNCTION · src
∀ :A. IO :A → IO (Result Dynamic :A)(WITH-RUN-IN-IO_) FUNCTION · src
∀ :M :A :B. UnliftIo :M IO ⇒ ((:M :A → IO :A) → IO :B) → :M :B`with-run-in-io`, but pegged to the simple-io implementation. Useful when you need to unlift, run, then immediately re-run a function. See, e.g., io-file:with-open-file%.
Macros
DO-MAP-INTO-IO_ ((VAR LST) &BODY BODY) MACRO
DO-TIMES-IO_ (N &BODY BODY) MACRO
Efficiently perform an IO operation N times.
DO-FOREACH-IO_ ((VAR-SYM INTO-ITR) &BODY BODY) MACRO
Efficiently perform a monadic operation for each element of an iterator. More efficient than foreach-io, if your effect can run in IO. VAR-SYM is bound to the value of the element in the iterator.
Package IO/RESOURCE
Types
ExitCase TYPE · src
CompletedErrored
Signals the exit condition for an effectful computation using some resource.
Instances
Values
(BRACKET-LIFECYCLE-MASKED ACQUIRE-OP RELEASE-OP COMPUTATION-OP) FUNCTION · src
∀ :RT :T :M :R :A :B. (Exceptions :M) (Threads :RT :T :M) ⇒ :M :R * (:R → :M :A) * (:R → :M :B) → :M :BAcquire a resource, run a computation with it, and release it. Guarantees that RELEASE-OP will run if ACQUIRE-OP completes. If COMPUTATION-OP raises an exception, it will be re-raised after the resource cleans up. If ACQUIRE-OP or RELEASE-OP raise an exception, then release is not guaranteed. RELEASE-OP receives only the acquired resource. Concurrent: - Masks the thread during resource acquisition and release. - The computation is not maskedbut and if another thread stops this one during the computation then the resource the resource will still be released.
(BRACKET-LIFECYCLE-MASKED-CASE ACQUIRE-OP RELEASE-OP COMPUTATION-OP) FUNCTION · src
∀ :RT :T :M :R :A :B. (Exceptions :M) (Threads :RT :T :M) ⇒ :M :R * (:R * ExitCase → :M :A) * (:R → :M :B) → :M :BAcquire a resource, run a computation with it, and release it. Guarantees that RELEASE-OP will run if ACQUIRE-OP completes. If COMPUTATION-OP raises an exception, it will be re-raised after the resource cleans up. If ACQUIRE-OP or RELEASE-OP raise an exception, then release is not guaranteed. RELEASE-OP receives both the acquired resource and an ExitCase indicating whether the computation completed successfully (Completed) or errored (Errored). Concurrent: - Masks the thread during resource acquisition and release. - The computation is not masked, but if another thread stops this one during the computation then the resource the resource will still be released.
(BRACKET-MASKED ACQUIRE-OP RELEASE-OP COMPUTATION-OP) FUNCTION · src
∀ :RT :T :M :R :A :B. (Exceptions :M) (Threads :RT :T :M) ⇒ :M :R * (:R → :M :A) * (:R → :M :B) → :M :BAcquire a resource, run a computation with it, and release it. Guarantees that RELEASE-OP will run if ACQUIRE-OP completes. If COMPUTATION-OP raises an exception, it will be re-raised after the resource cleans up. If ACQUIRE-OP or RELEASE-OP raise an exception, then release is not guaranteed. RELEASE-OP receives only the acquired resource. Concurrent: - Masks the thread before ACQUIRE-OP starts. - Unmasks the thread after RELEASE-OP finishes.
(BRACKET-MASKED-CASE ACQUIRE-OP RELEASE-OP COMPUTATION-OP) FUNCTION · src
∀ :RT :T :M :R :A :B. (Exceptions :M) (Threads :RT :T :M) ⇒ :M :R * (:R * ExitCase → :M :A) * (:R → :M :B) → :M :BAcquire a resource, run a computation with it, and release it. Guarantees that RELEASE-OP will run if ACQUIRE-OP completes. If COMPUTATION-OP raises an exception, it will be re-raised after the resource cleans up. If ACQUIRE-OP or RELEASE-OP raise an exception, then release is not guaranteed. RELEASE-OP receives both the acquired resource and an ExitCase indicating whether the computation completed successfully (Completed) or errored (Errored). Concurrent: - Masks the thread before ACQUIRE-OP starts. - Unmasks the thread after RELEASE-OP finishes.
(BRACKET-UNMASKED ACQUIRE-OP RELEASE-OP COMPUTATION-OP) FUNCTION · src
∀ :RT :T :M :R :A :B. (Exceptions :M) (Threads :RT :T :M) ⇒ :M :R * (:R → :M :A) * (:R → :M :B) → :M :BAcquire a resource, run a computation with it, and release it. Guarantees that RELEASE-OP will run if ACQUIRE-OP completes. If COMPUTATION-OP raises an exception, it will be re-raised after the resource cleans up. If ACQUIRE-OP or RELEASE-OP raise an exception, then release is not guaranteed. RELEASE-OP receives only the acquired resource.
(BRACKET-UNMASKED-CASE ACQUIRE-OP RELEASE-OP COMPUTATION-OP) FUNCTION · src
∀ :RT :T :M :R :A :B. (Exceptions :M) (Threads :RT :T :M) ⇒ :M :R * (:R * ExitCase → :M :A) * (:R → :M :B) → :M :BAcquire a resource, run a computation with it, and release it. Guarantees that RELEASE-OP will run if ACQUIRE-OP completes. If COMPUTATION-OP raises an exception, it will be re-raised after the resource cleans up. If ACQUIRE-OP or RELEASE-OP raise an exception, then release is not guaranteed. RELEASE-OP receives both the acquired resource and an ExitCase indicating whether the computation completed successfully (Completed) or errored (Errored).
Package IO/MUT
Classes
MutableVar CLASS · src
Monad :M ⇒ MutableVar :MMethods:
NEW-VAR :: :A → :M (Var :A)
Create a new variable with an initial value.READ :: Var :A → :M :A
Read the current value stored in a variable.WRITE :: Var :A * :A → :M :A
Set the value in a variable and return the old value.MODIFY :: Var :A * (:A → :A) → :M :A
Modify the value in a variable by applying F, and return the old value.
Instances
MutableVar :M ⇒ MutableVar (FreeT TermStubF :M)MutableVar IOMutableVar :M ⇒ MutableVar (LoopT :M)MutableVar :M ⇒ MutableVar (EnvT :E :M)MutableVar :M ⇒ MutableVar (StateT :S :M)
Macros
IMPLEMENT-MUTABLE-VAR (MONAD) MACRO
DERIVE-MUTABLE-VAR (MONAD-PARAM MONADT-FORM) MACRO
Automatically derive an instance of MutableVar for a monad transformer. Example: (derive-mutable-var :m (st:StateT :s :m))
Package IO/TERM
Macros
DERIVE-TERMINAL (MONAD-PARAM MONADT-FORM) MACRO
Automatically derive an instance of Terminal for a monad transformer. Example: (derive-terminal :m (st:StateT :s :m))
IMPLEMENT-TERMINAL (MONAD) MACRO
Package IO/RANDOM
Classes
Random CLASS · src
Monad :M ⇒ Random :MMethods:
MAKE-RANDOM-STATE :: :M RandomState
Create a fresh random state.COPY-RANDOM-STATE :: RandomState → :M RandomState
Create a copy of another random state, starting at the same seed.GET-CURRENT-RANDOM-STATE :: :M RandomState
Get the current thread's random state.SET-CURRENT-RANDOM-STATE :: RandomState → :M Unit
Set the current thread's random state.RANDOM :: RandomLimit :A ⇒ RandomState * :A → :M :A
Generate a random value less than LIMIT using the given random state.RANDOM_ :: RandomLimit :A ⇒ :A → :M :A
Generate a random value less than LIMIT using the current random state.
Instances
RandomLimit CLASS · src
Num :A ⇒ RandomLimit :AA number that can be used to bound a random number value.
Instances
Macros
IMPLEMENT-RANDOM (MONAD) MACRO
DERIVE-RANDOM (MONAD-PARAM MONADT-FORM) MACRO
Automatically derive an instance of Random for a monad transformer. Example: (derive-random :m (st:StateT :s :m))
Package IO/THREAD
Types
ForkScope TYPE · src
Controls whether a forked thread is attached to a scope, and if so which one. - Structured: Attach to the current thread's scope. - StructuredIn: Attach to the provided thread handle's scope. - Detached: Attach to the global scope; the thread will end with the toplevel run!.
Instances
RuntimeRepr (ForkScope :|0|)
Generation TYPE · src
Instances
TimeoutStrategy TYPE · src
Controls whether blocking IO operations use a timeout in milliseconds.
Instances
UnhandledExceptionStrategy TYPE · src
Controls what happens when a forked thread raises an exception that is not a ThreadingException. - ThrowException: Immediately throws the Dynamic value in the child thread. - LogAndSwallow: Logs the exception to *ERROR-OUTPUT* and ignore it until/if joined. - Swallow: Ignore the error until/if joined.
UnmaskFinallyMode TYPE · src
When a thread unmasks and calls a cleanup operation, the thread is either: * Still running, and will cleanup and continue * Received a stop while it was masked, and will cleanup and then terminate itself.
Structs
ForkStrategy #<COALTON-IMPL/TYPECHECKER/TYPES:TYVAR :T> STRUCT · src
Strategy object controlling fork behavior (exception semantics + structured concurrency).
Instances
RuntimeRepr (ForkStrategy :|0|)
IoThread STRUCT · src
Classes
Concurrent CLASS · src
Concurrent :C :AA Concurrent has thread-like semantics. It can be stopped, masked, unmasked, and await-ed. Concurrents don't have a uniform fork function, becasue they require different initialization input.
Methods:STOP :: (Exceptions :M) (Threads :RT :T :M) ⇒ :C → :M Unit
Stop a Concurrent. If the Concurrent has already stopped, does nothing. If the Concurrent is masked, this will pend a stop on the Concurrent. When/if the Concurrent becomes completely unmaksed, it will stop iself. Regardless of whether the target Concurrent is masked, STOP does not block or wait for the target to complete.AWAIT :: (Exceptions :M) (Threads :RT :T :M) ⇒ :C → :M :A
Block the current thread until the target Concurrent is completed, and retrieve its value. Re-raises if the target Concurrent raised an unhandled exceptionMASK :: (Exceptions :M) (Threads :RT :T :M) ⇒ :C → :M Unit
Mask the Concurrent so it can't be stopped.UNMASK :: (Exceptions :M) (Threads :RT :T :M) ⇒ :C → :M Unit
Unmask the Concurrent so it can be stopped. Unmask respects nested masks - if the Concurrent has been masked N times, it can only be stopped after being unmasked N times. When the Concurrent unmasks, if there are any pending stops, it will immediately stop itself.UNMASK-FINALLY :: (UnliftIo :R :IO) (LiftTo :R :M) (Threads :RT :T :R) (Exceptions :M) (Threads :RT :T :M) ⇒ :C * (UnmaskFinallyMode → :R Unit) → :M Unit
Unmask the thread, run the provided action, and then honor any pending stop for that thread after the action finishes. Warning: There is a very small chance that the UnmaskFinallyMode passed to the callback could be inconsistent with whether the Concurrent is ultimately stopped. Regardless of the input, the callback should leave any resources in a valid state. An example of a valid callback: closing a log file if the thread is stopped, or closing the log file with a final message if the thread is continuing.
Instances
(Concurrent (ConcurrentGroup :T Unit) (List Unit)) (Scheduler :S) ⇒ Concurrent (WorkerPool :S :I :T) UnitConcurrent :C :A ⇒ Concurrent (ConcurrentGroup :C :A) (List :A)Concurrent (Future :A) :AConcurrent IoThread Unit
Runtime CLASS · src
Runtime :R :TThis class doesn't represent data, but the type tells a Concurrent and a Threads how to hook into the native threading implementations that a runtime provides. A runtime has a 'base' concurrent, which is the underlying thread/fiber/etc. that the runtime produces to run concurrently. All other Concurrents are built by composing on the base concurrent somehow. Runtime is a low-level type that operates inside the normal MonadIo layer. It should not be used by normal application code. Its two main purposes are: (1) to make Threads generic over the type of thread it forks, and (2) to build low-level, efficient concurrency tools that are generic over the underlying thread type.
Methods:CURRENT-THREAD! :: Proxy :R → :T
Get a handle for the current thread.SLEEP! :: Proxy :R * UFix → Void
Sleep the current thread for MSECS milliseconds.FORK! :: Proxy :R * ForkStrategy :T * (Void → Result Dynamic :A) → :T
Spawn a new thread, which starts running immediately. Returns the handle to the thread. The ForkStrategy controls both: - how unhandled exceptions behave, and - whether the fork is structured (and which thread's scope owns it).JOIN! :: Proxy :R * :T → Result Dynamic Unit
Block the current thread until the target thread is completed. Does not a retrieve value. Raises an exception if the target thread raised an unhandled exception, wrapping the target thread's raised exception. JOIN! is the lowest level operation to block on another thread's termination, and most code should use AWAIT instead.STOP! :: Proxy :R * :T → Void
Stop a :t. If the thread has already stopped, does nothing. If the :t is masked, this will pend a stop on the :t. When/if the :t becomes completely unmaksed, it will stop iself. Regardless of whether the target :t is masked, STOP does not block or wait for the target thread to complete.MASK! :: Proxy :R * :T → Void
Mask the thread so it can't be stopped.UNMASK! :: Proxy :R * :T → Void
Unmask the thread so it can be stopped. Unmask respects nested masks - if the thread has been masked N times, it can only be stopped after being unmasked N times. When the thread unmasks, if there are any pending stops, it will immediately be stopped.UNMASK-FINALLY! :: Proxy :R * :T * (UnmaskFinallyMode → Void) → Void
Unmask the thread, run the provided action, and then honor any pending stop for that thread after the action finishes. Warning: There is a very small chance that the UnmaskFinallyMode passed to the callback could be inconsistent with whether the Concurrent is ultimately stopped. Regardless of the input, the callback should leave any resources in a valid state. An example of a valid callback: closing a log file if the thread is stopped, or closing the log file with a final message if the thread is continuing.PARK-CURRENT-THREAD-IF! :: Proxy :R * (Generation → Void) * (Void → Boolean) &key (:timeout TimeoutStrategy) → Void
Parks the current thread if SHOULD-PARK? returns True. Will park the thread until woken by an unpark from another thread. Upon an unpark, the thread will resume even if SHOULD-PARK? is False! SHOULD-PARK? is only checked to determine if the thread should park, *not* if it should resume. Can specify a timeout. Concurrent: - WARNING: SHOULD-PARK? must not block, or the thread could be left blocked in a masked state. - Can briefly block while trying to park the thread, if contended.UNPARK-THREAD! :: Proxy :R * Generation * :T → Void
Unparks the thread if it is still waiting on the generation. Attempting to unpark the thread with a stale generation has no effect. A generation will be stale if the thread has unparked and re-parked since the initial park. Concurrent: - Can briefly block while trying to unpark the thread, if contended.
Threads CLASS · src
(MonadIo :M) (Runtime :RT :T) ⇒ Threads :RT :T :MA MonadIo which can spawn :t's. Other :t's error separately. A spawned :t erroring will not cause the parent :t to fail. :t can be any 'thread-like' object, depending on the underlying implementation - system threads, software-managed green threads, etc.
Instances
Threads :RUNTIME :THREAD :M ⇒ Threads :RUNTIME :THREAD (FreeT TermStubF :M)Threads IoRuntime IoThread IOThreads :RUNTIME :THREAD :M ⇒ Threads :RUNTIME :THREAD (LoopT :M)Threads :RUNTIME :THREAD :M ⇒ Threads :RUNTIME :THREAD (EnvT :E :M)Threads :RUNTIME :THREAD :M ⇒ Threads :RUNTIME :THREAD (StateT :S :M)
Values
CURRENT-THREAD VALUE · src
∀ :RT :M :T. Threads :RT :T :M ⇒ :M :TGet the current thread.
(FORK-THREAD OP) FUNCTION · src
∀ :I :RT :R :A :T :M. (UnliftIo :R :I) (LiftTo :R :M) (Threads :RT :T :R) ⇒ :R :A &key (:scope ForkScope :T) (:unhandled UnhandledExceptionStrategy) → :M :TSpawn a new thread, which starts running immediately. Returns the handle to the thread. Can specify an unhandled exception strategy and fork scope. If the thread raises an unhandled exception, the default behavior is to log it to *ERROR-OUTPUT* and swallow it until/if the thread is joined. The default fork scope is structured.
(JOIN-THREAD THREAD) FUNCTION · src
∀ :RT :T :M. (Threads :RT :T :M) (Exceptions :M) ⇒ :T → :M UnitBlock the current thread until the target thread is completed. Does not a retrieve value. Raises an exception if the target thread raised an unhandled exception, wrapping the target thread's raised exception. JOIN-THREAD is the lowest level operation to block on another thread's termination.
(MASK-CURRENT! RT-PRX) FUNCTION · src
∀ :T :RT. Runtime :RT :T ⇒ Proxy :RT → VoidMask the current thread.
MASK-CURRENT-THREAD VALUE · src
∀ :RT :T :M. Threads :RT :T :M ⇒ :M UnitMask the current thread so it can't be stopped.
(MASK-THREAD THREAD) FUNCTION · src
∀ :RT :T :M. Threads :RT :T :M ⇒ :T → :M UnitMask the thread so it can't be stopped.
(PARK-CURRENT-THREAD-IF WITH-GEN SHOULD-PARK?) FUNCTION · src
∀ :RT :T :IO :M. (BaseIo :IO) (Threads :RT :T :IO) (MonadIo :M) ⇒ (Generation → :IO Unit) * :IO Boolean &key (:timeout TimeoutStrategy) → :M UnitParks the current thread if SHOULD-PARK? returns True. Will park the thread until woken by an unpark from another thread. Upon an unpark, the thread will resume even if SHOULD-PARK? is False! SHOULD-PARK? is only checked to determine if the thread should park, *not* if it should resume. Can specify a timeout. Concurrent: - WARNING: SHOULD-PARK? must not block, or the thread could be left blocked in a masked state. - Can briefly block while trying to park the thread, if contended.
(SLEEP MSEC) FUNCTION · src
∀ :RT :T :M. Threads :RT :T :M ⇒ UFix → :M UnitSleep the current thread for MSECS milliseconds.
(STOP-THREAD THREAD) FUNCTION · src
∀ :RT :T :M. Threads :RT :T :M ⇒ :T → :M UnitStop a thread. If the thread has already stopped, does nothing.
(UNMASK-CURRENT! RT-PRX) FUNCTION · src
∀ :T :RT. Runtime :RT :T ⇒ Proxy :RT → VoidUnmask the current thread.
UNMASK-CURRENT-THREAD VALUE · src
∀ :RT :T :M. Threads :RT :T :M ⇒ :M UnitUnmask the current thread so it can be stopped. Unmask respects nested masks - if the thread has been masked N times, it can only be stopped after being unmasked N times.
(UNMASK-CURRENT-THREAD-FINALLY OP-FINALLY) FUNCTION · src
∀ :IO :RT :T :R :M. (UnliftIo :R :IO) (LiftTo :R :M) (Threads :RT :T :R) ⇒ (UnmaskFinallyMode → :R Unit) → :M UnitUnmask the current thread, run the provided action, and then honor any pending stop for that thread after the action finishes. Warning: There is a very small chance that the UnmaskFinallyMode passed to the callback could be inconsistent with whether the Concurrent is ultimately stopped. Regardless of the input, the callback should leave any resources in a valid state. An example of a valid callback: closing a log file if the thread is stopped, or closing the log file with a final message if the thread is continuing.
(UNMASK-THREAD THREAD) FUNCTION · src
∀ :RT :T :M. Threads :RT :T :M ⇒ :T → :M UnitUnmask the thread so it can be stopped. Unmask respects nested masks - if the thread has been masked N times, it can only be stopped after being unmasked N times.
(UNMASK-THREAD-FINALLY THREAD OP-FINALLY) FUNCTION · src
∀ :IO :RT :T :R :M. (UnliftIo :R :IO) (LiftTo :R :M) (Threads :RT :T :R) ⇒ :T * (UnmaskFinallyMode → :R Unit) → :M UnitUnmask the thread, run the provided action, and then honor any pending stop for that thread after the action finishes. Warning: There is a very small chance that the UnmaskFinallyMode passed to the callback could be inconsistent with whether the Concurrent is ultimately stopped. Regardless of the input, the callback should leave any resources in a valid state. An example of a valid callback: closing a log file if the thread is stopped, or closing the log file with a final message if the thread is continuing.
(UNPARK-THREAD GEN THREAD) FUNCTION · src
∀ :RT :T :M. Threads :RT :T :M ⇒ Generation * :T → :M UnitUnparks the thread if it is still waiting on the generation. Attempting to unpark the thread with a stale generation has no effect. A generation will be stale if the thread has unparked and re-parked since the initial park. Concurrent: - Can briefly block while trying to unpark the thread, if contended.
(WITH-MASK OP) FUNCTION · src
∀ :RT :T :M :A. (Threads :RT :T :M) (Exceptions :M) ⇒ :M :A → :M :AMask the current thread while running OP, unmasking afterward.
(WRITE-LINE-SYNC MSG) FUNCTION · src
∀ :S :M. (Into :S String) (Terminal :M) ⇒ :S → :M UnitPerform a synchrozied write-line to the terminal. Not performant - mainly useful for debugging.
(FORK-THREAD_ OP) FUNCTION · src
∀ :A :M. (Threads IoRuntime IoThread :M) (LiftTo IO :M) ⇒ IO :A &key (:scope ForkScope IoThread) (:unhandled UnhandledExceptionStrategy) → :M IoThreadSpawn a new IoThread. Can specify an unhandled exception strategy and fork scope.
(PARK-CURRENT-THREAD-IF_) FUNCTION · src
∀ :M. MonadIo :M ⇒ (Generation → IO Unit) * IO Boolean &key (:timeout TimeoutStrategy) → :M UnitParks the current thread if SHOULD-PARK? returns True. Will park the thread until woken by an unpark from another thread. Upon an unpark, the thread will resume even if SHOULD-PARK? is False! SHOULD-PARK? is only checked to determine if the thread should park, *not* if it should resume. Concurrent: - WARNING: SHOULD-PARK? must not block, or the thread could be left blocked in a masked state. - Can briefly block while trying to park the thread, if contended.
(UNMASK-FINALLY_) FUNCTION · src
∀ :A :C :M. (LiftTo IO :M) (Exceptions :M) (Concurrent :C :A) (Threads IoRuntime IoThread :M) ⇒ :C * (UnmaskFinallyMode → IO Unit) → :M Unit(UNMASK-THREAD-FINALLY_) FUNCTION · src
∀ :M. (LiftTo IO :M) (Exceptions :M) (Threads IoRuntime IoThread :M) ⇒ IoThread * (UnmaskFinallyMode → IO Unit) → :M UnitMacros
DO-FORK-THREAD_ (&BODY FORMS) MACRO
DO-WITH-MASK (&BODY BODY) MACRO
Evaluate BODY with the current thread masked, automatically unmasking afterward.
DO-FORK-THREAD (&BODY FORMS) MACRO
DERIVE-THREADS (MONAD-PARAM MONADT-FORM) MACRO
Automatically derive an instance of Threads for a monad transformer. Example: (derive-threads :m (st:StateT :s :m))
Package IO/FILE
Classes
Files CLASS · src
MonadIo :M ⇒ Files :MMethods:
EXISTS? :: Into :A Pathname ⇒ :A → :M (Result FileError Boolean)
Returns whether a file or directory exists.FILE-EXISTS? :: Into :A Pathname ⇒ :A → :M (Result FileError Boolean)
Returns True if a pathname names a file that exists.DIRECTORY-EXISTS? :: Into :A Pathname ⇒ :A → :M (Result FileError Boolean)
Returns True if a pathname names a directory that exists.OPEN :: File :A ⇒ Pathname &key (:direction OpenDirection) (:if-exists IfExists) → :M (Result FileError (FileStream :A))CLOSE :: FileStream :A → :M (Result FileError :B)
Closes a FileStream.ABORT :: FileStream :A → :M (Result FileError :B)
Closes a FileStream and aborts all operations..CREATE-TEMP-DIRECTORY :: :M (Result FileError Pathname)CREATE-TEMP-FILE :: String → :M (Result FileError Pathname)COPY :: (Into :A Pathname) (Into :B Pathname) ⇒ :A * :B → :M (Result FileError Unit)
Copies a file to a new location.CREATE-DIRECTORY :: Into :P Pathname ⇒ :P → :M (Result FileError Pathname)
This is equivalent to `mkdir -p`. Creates a directory and its parents. The pathname must be a valid directory pathname.DELETE-FILE :: Into :P Pathname ⇒ :P → :M (Result FileError Unit)
Deletes a given file if the file exists.REMOVE-DIRECTORY :: Into :P Pathname ⇒ :P → :M (Result FileError :P)
Deletes an empty directory.REMOVE-DIRECTORY-RECURSIVE :: Into :P Pathname ⇒ :P → :M (Result FileError Unit)
Deletes a target directory recursively. Equivalent to `rm -r`. Errors if the path is not a directory.SYSTEM-RELATIVE-PATHNAME :: Into :SYS String ⇒ :SYS * String → :M (Result FileError Pathname)
Generates a system-relative-pathname for a given filename or path. This is a wrapper for `asdf:system-relative-pathname`. `Name` will likely be an empty string unless a subdirectory or filename is specified.READ-FILE-TO-STRING :: Into :P Pathname ⇒ :P → :M (Result FileError String)
Reads a file into a string, given a pathname string.READ-FILE-LINES :: Into :P Pathname ⇒ :P → :M (Result FileError (List String))
Reads a file into lines, given a pathname or string.READ-CHAR :: FileStream Char → :M (Result FileError Char)
Reads a character from an FileStream.READ-LINE :: FileStream Char → :M (Result FileError String)WRITE-CHAR :: FileStream Char * Char → :M (Result FileError Unit)
Writes a `Char` to the stream.WRITE-LINE :: FileStream Char * String → :M (Result FileError Unit)
Writes a string with an appended newline to a filestream of type Char.WRITE-STRING :: FileStream Char * String → :M (Result FileError Unit)
Writes a `string` to a FileStream of type Char.READ-FILE-TO-VECTOR :: File :A ⇒ FileStream :A → :M (Result FileError (Vector :A))
Reads a file into a vector of type `:a`.READ-VECTOR :: File :A ⇒ FileStream :A * UFix → :M (Result FileError (Vector :A))
Reads a chunk of a file into a vector of type `:a`.WRITE-VECTOR :: (File :A) (RuntimeRepr :A) ⇒ FileStream :A * Vector :A → :M (Result FileError Unit)
Writes elements of an vector of type `:a` to a stream of type `:a`.WRITE-TO-FILE :: (Into :P Pathname) (File :A) (RuntimeRepr :A) ⇒ :P * Vector :A → :M (Result FileError Unit)
Opens and writes to a file with data of type :a. Supersedes existing data on the file.APPEND-TO-FILE :: (Into :P Pathname) (File :A) (RuntimeRepr :A) ⇒ :P * Vector :A → :M (Result FileError Unit)
Opens and appends a file with data of type :a.SET-FILE-POSITION :: FileStream :A * UFix → :M (Result FileError Unit)
Sets the file position of a file stream.
Values
(WITH-OPEN-FILE PTH K) FUNCTION · src
∀ :I :RT :T :P :A :R :B :M. (File :A) (Files :I) (UnliftIo :R :I) (Into :P Pathname) (LiftTo :R :M) (Exceptions :I) (Threads :RT :T :I) ⇒ :P * (FileStream :A → :R :B) &key (:direction OpenDirection) (:if-exists IfExists) → :M :BOpens a file stream, performs K on it, then closes the stream. Can run any underlying BaseIo, which can be useful but can also cause inference issues in some cases. Try WITH-OPEN-FILE_ if you have issues.
(WITH-TEMP-DIRECTORY K) FUNCTION · src
∀ :I :RT :T :R :A :M. (UnliftIo :R :I) (LiftTo :R :M) (Exceptions :I) (Files :I) (Threads :RT :T :I) ⇒ (Pathname → :R :A) → :M :APerforms an operation `thunk` inside a temporary directory. Can run any underlying BaseIo, which can be useful but can also cause inference issues in some cases. Try WITH-TEMP-DIRECTORY_ if you have issues.
(WITH-TEMP-FILE K) FUNCTION · src
∀ :I :RT :T :A :R :B :M. (File :A) (Files :I) (Threads :RT :T :I) (UnliftIo :R :I) (LiftTo :R :M) (Exceptions :I) ⇒ (FileStream :A → :R :B) &key (:extension String) → :M :BPerforms an operation `thunk` on a temporary file. File type extensions need to include `.` Can run any underlying BaseIo, which can be useful but can also cause inference issues in some cases. Try WITH-TEMP-FILE_ if you have issues.
(WITH-OPEN-FILE_) FUNCTION · src
∀ :P :A :B :M. (File :A) (UnliftIo :M IO) (LiftTo IO :M) (Into :P Pathname) ⇒ :P * (FileStream :A → IO :B) &key (:direction OpenDirection) (:if-exists IfExists) → :M :B(WITH-TEMP-DIRECTORY_) FUNCTION · src
∀ :A :M. (UnliftIo :M IO) (LiftTo IO :M) ⇒ (Pathname → IO :A) → :M :A(WITH-TEMP-FILE_) FUNCTION · src
∀ :A :B :M. (File :A) (UnliftIo :M IO) (LiftTo IO :M) ⇒ (FileStream :A → IO :B) &key (:extension String) → :M :BMacros
DO-WITH-TEMP-DIRECTORY ((DIR) &BODY BODY) MACRO
`do` sugar for `with-temp-directory`.
DERIVE-FILES (MONAD-PARAM MONADT-FORM) MACRO
Derive a `Files` instance for MONADT-FORM by lifting into the base instance. Example: (derive-files :m (st:StateT :s :m))
DO-WITH-OPEN-FILE ((PATH FS &KEY (DIRECTION (QUOTE INPUT)) (IF-EXISTS (QUOTE EERROR))) &BODY BODY) MACRO
`do` sugar for `with-open-file`. Expands to a continuation where BODY runs in `do`. Usage: (do-with-open-file path (fs) (line <- (read-char fs)) ...) (do-with-open-file path (fs) :direction f_:Output :if-exists f_:Supersede (write-line fs "hello") ...)
DO-WITH-TEMP-DIRECTORY_ ((DIR) &BODY BODY) MACRO
`do` sugar for `with-temp-directory_`.
DO-WITH-OPEN-FILE_ ((PATH FS &KEY (DIRECTION (QUOTE INPUT)) (IF-EXISTS (QUOTE EERROR))) &BODY BODY) MACRO
`do` sugar for `with-open-file_`. Expands to a continuation where BODY runs in `do`. Usage: (do-with-open-file_ path (fs) (line <- (read-char fs)) ...) (do-with-open-file_ path (fs) :direction file:Output :if-exists file:Supersede (write-line fs "hello") ...)
DO-WITH-TEMP-FILE_ (TYPE (FS) &BODY BODY) MACRO
`do` sugar for `with-temp-file_` (TYPE is a string like "txt").
DO-WITH-TEMP-FILE (TYPE (FS) &BODY BODY) MACRO
`do` sugar for `with-temp-file` (TYPE is a string like "txt").
IMPLEMENT-FILES (MONAD) MACRO
Package IO/UNIQUE
Classes
UniqueGen CLASS · src
Monad :M ⇒ UniqueGen :MMethods:
NEW-UNIQUE :: :M Unique
Generate a value that will be unique within this run of the program. Threadsafe - calling from different threads will still result in unique values across all threads.
Values
(TO-INT (UNIQUE% I)) FUNCTION · src
Unique → IntegerConvert a unique value to an integer. It is guaranteed that: (/= (to-int a) (to-int b)) for any two different Unique instances.
Macros
IMPLEMENT-UNIQUE-GEN (MONAD) MACRO
DERIVE-UNIQUE-GEN (MONAD-PARAM MONADT-FORM) MACRO
Automatically derive an instance of UniqueGen for a monad transformer. Example: (derive-unique-gen :m (st:StateT :s :m))
Package IO/NETWORK
Types
ByteConnectionSocket TYPE · src
A socket connecting a client and server using a byte stream.
Instances
ByteServerSocket TYPE · src
A server socket listening for new byte-stream connections.
Instances
ConnectionSocket TYPE · src
A socket connecting a client and server.
Instances
NetworkException TYPE · src
ServerSocket TYPE · src
A server socket listening for new connections.
Instances
Classes
Sockets CLASS · src
MonadIo :M ⇒ Sockets :MMethods:
SOCKET-LISTEN :: String * UFix → :M ServerSocket
Start a new server socket, listening on HOSTNAME and PORT.SOCKET-ACCEPT :: ServerSocket → :M ConnectionSocket
Accept a connection with a new client.SOCKET-CONNECT :: String * UFix → :M ConnectionSocket
Connect to a server at HOSTNAME and PORT, returning a new connection.CLOSE-CONNECTION :: ConnectionSocket → :M Unit
Close an open connection socket.CLOSE-SERVER :: ServerSocket → :M Unit
Close an open server socket.WRITE-LINE :: Into :S String ⇒ :S * ConnectionSocket → :M UnitREAD-LINE :: ConnectionSocket → :M String
Read the next line from the socket. Blocks until data is sent!BYTE-SOCKET-LISTEN :: String * UFix → :M ByteServerSocket
Start a new server socket for byte-stream connections, listening on HOSTNAME and PORT.BYTE-SOCKET-ACCEPT :: ByteServerSocket → :M ByteConnectionSocket
Accept a byte-stream connection with a new client.BYTE-SOCKET-CONNECT :: String * UFix → :M ByteConnectionSocket
Connect to a server at HOSTNAME and PORT using a byte stream, returning a new connection.CLOSE-BYTE-CONNECTION :: ByteConnectionSocket → :M Unit
Close an open byte-stream connection socket.CLOSE-BYTE-SERVER :: ByteServerSocket → :M Unit
Close an open byte-stream server socket.WRITE-BYTES :: Vector U8 * ByteConnectionSocket → :M Unit
Write all bytes in the vector to the socket.READ-EXACTLY :: UFix * ByteConnectionSocket → :M (Vector U8)
Read exactly N bytes from the socket. Blocks until N bytes are available.
Values
(BYTE-SOCKET-ACCEPT-FORK-WITH SERVER-SOCKET OP) FUNCTION · src
∀ :RT :M :A :T. (Sockets :M) (Threads :RT :T :M) (Exceptions :M) (UnliftIo :M :M) ⇒ ByteServerSocket * (ByteConnectionSocket → :M :A) → :M :TAccept a byte-stream connection with a new client and run operation OP on a new thread. Guarantees that the socket will close on cleanup. Returns a handle to the forked thread.
(BYTE-SOCKET-ACCEPT-WITH SERVER-SOCKET OP) FUNCTION · src
∀ :RT :T :M :A. (Sockets :M) (Threads :RT :T :M) (Exceptions :M) ⇒ ByteServerSocket * (ByteConnectionSocket → :M :A) → :M :AAccept a byte-stream connection with a new client and run operation OP. Guarantees that the socket will close on cleanup. Note: If you fork a thread inside this, the operation on this thread will probably finish and close the socket before you intend. For multithreaded uses, use byte-socket-accept-fork-with.
(BYTE-SOCKET-CONNECT-WITH HOSTNAME PORT OP) FUNCTION · src
∀ :RT :T :M :A. (Sockets :M) (Threads :RT :T :M) (Exceptions :M) ⇒ String * UFix * (ByteConnectionSocket → :M :A) → :M :ARun operation OP with a byte-stream connection to an open server socket at HOSTNAME and PORT. Guarantees that the socket will close on cleanup.
(BYTE-SOCKET-LISTEN-WITH HOSTNAME PORT OP) FUNCTION · src
∀ :RT :T :M :A. (Sockets :M) (Threads :RT :T :M) (Exceptions :M) ⇒ String * UFix * (ByteServerSocket → :M :A) → :M :ARun operation OP with a new byte-stream server socket, listening on HOSTNAME and PORT. Guarantees that the socket will close on cleanup.
(SOCKET-ACCEPT-FORK-WITH SERVER-SOCKET OP) FUNCTION · src
∀ :RT :M :A :T. (Sockets :M) (Threads :RT :T :M) (Exceptions :M) (UnliftIo :M :M) ⇒ ServerSocket * (ConnectionSocket → :M :A) → :M :TAccept a connection with a new client and run operation OP on a new thread. Guarantees that the socket will close on cleanup. Returns a handle to the forked thread.
(SOCKET-ACCEPT-WITH SERVER-SOCKET OP) FUNCTION · src
∀ :RT :T :M :A. (Sockets :M) (Threads :RT :T :M) (Exceptions :M) ⇒ ServerSocket * (ConnectionSocket → :M :A) → :M :AAccept a connection with a new client and run operation OP. Guarantees that the socket will close on cleanup. Note: If you fork a thread inside this, the operation on this thread will probably finish and close the socket before you intend. For multithreaded uses, use socket-accept-fork-with.
(SOCKET-CONNECT-WITH HOSTNAME PORT OP) FUNCTION · src
∀ :RT :T :M :A. (Sockets :M) (Threads :RT :T :M) (Exceptions :M) ⇒ String * UFix * (ConnectionSocket → :M :A) → :M :ARun operation OP with a connection to an open server socket at HOSTNAME and PORT. Guarantees that the socket will close on cleanup.
(SOCKET-LISTEN-WITH HOSTNAME PORT OP) FUNCTION · src
∀ :RT :T :M :A. (Sockets :M) (Threads :RT :T :M) (Exceptions :M) ⇒ String * UFix * (ServerSocket → :M :A) → :M :ARun operation OP with a new server socket, listening on HOSTNAME and PORT. Guarantees that the socket will close on cleanup.
Macros
DERIVE-SOCKETS (MONAD-PARAM MONADT-FORM) MACRO
Automatically derive an instance of Sockets for a monad transformer. Example: (derive-sockets :m (st:StateT :s :m))
DO-BYTE-SOCKET-ACCEPT-FORK-WITH ((SOCKET-SYM (SERVER-SOCKET)) &BODY BODY) MACRO
Accept a byte-stream connection with a new client and run operation OP on a new thread. Guarantees that the socket will close on cleanup. Returns a handle to the forked thread.
DO-SOCKET-LISTEN-WITH ((SOCKET-SYM (HOSTNAME PORT)) &BODY BODY) MACRO
Run operation OP with a new server socket, listening on HOSTNAME and PORT. Guarantees that the socket will close on cleanup.
DO-SOCKET-ACCEPT-FORK-WITH ((SOCKET-SYM (SERVER-SOCKET)) &BODY BODY) MACRO
Accept a connection with a new client and run operation OP on a new thread. Guarantees that the socket will close on cleanup. Returns a handle to the forked thread.
DO-SOCKET-CONNECT-WITH ((SOCKET-SYM (HOSTNAME PORT)) &BODY BODY) MACRO
Run operation OP with a connection to an open server socket at HOSTNAME and PORT. Guarantees that the socket will close on cleanup.
DO-SOCKET-ACCEPT-WITH ((SOCKET-SYM (SERVER-SOCKET)) &BODY BODY) MACRO
Accept a connection with a new client and run operation OP. Guarantees that the socket will close on cleanup. Note: If you fork a thread inside this, the operation on this thread will probably finish and close the socket before you intend. For multithreaded uses, use socket-accept-fork-with.
DO-BYTE-SOCKET-ACCEPT-WITH ((SOCKET-SYM (SERVER-SOCKET)) &BODY BODY) MACRO
Accept a byte-stream connection with a new client and run operation OP. Guarantees that the socket will close on cleanup. Note: If you fork a thread inside this, the operation on this thread will probably finish and close the socket before you intend. For multithreaded uses, use byte-socket-accept-fork-with.
IMPLEMENT-SOCKETS (MONAD) MACRO
DO-BYTE-SOCKET-LISTEN-WITH ((SOCKET-SYM (HOSTNAME PORT)) &BODY BODY) MACRO
Run operation OP with a new byte-stream server socket, listening on HOSTNAME and PORT. Guarantees that the socket will close on cleanup.
DO-BYTE-SOCKET-CONNECT-WITH ((SOCKET-SYM (HOSTNAME PORT)) &BODY BODY) MACRO
Run operation OP with a byte-stream connection to an open server socket at HOSTNAME and PORT. Guarantees that the socket will close on cleanup.
Package IO/CONC/PARKING
Types
ParkingSet TYPE · src
ParkingSet is a thread-safe list of parked threads. A parking thread can atomically subscibe and park on a Parking Set, and a signalling thread can atomically unpark all parkers on a ParkingSet. In general, ParkingSet is the preferred way to park and unpark threads. The lower-level parking functions exposed by the Threads and Runtime classes should only be used if ParkingSet doesn't provide enough functionality for the algorithm. Concurrent: - ParkingSet's algorithms are lock free, but individual threads can block for a very short window if contention on the parking set is very high.
Instances
Values
NEW-PARKING-SET VALUE · src
∀ :M. MonadIo :M ⇒ :M ParkingSetCreate a new ParkingSet.
(PARK-IN-SET-IF SHOULD-PARK? PSET) FUNCTION · src
∀ :RT :T :IO :M. (BaseIo :IO) (Threads :RT :T :IO) (MonadIo :M) ⇒ :IO Boolean * ParkingSet &key (:timeout TimeoutStrategy) → :M UnitParks the current thread in PSET if SHOULD-PARK? returns True. Will park the thread until woken by an unpark from another thread. Upon an unpark, the thread will resume even if SHOULD-PARK? is False! SHOULD-PARK? is only checked to determine if the thread should park, *not* if it should resume. Can specify a timeout. Concurrent: - WARNING: SHOULD-PARK? must not block, or the thread could be left blocked in a masked state. - Can briefly block while trying to park the thread, if contended.
(PARK-IN-SETS-IF SHOULD-PARK? PSETS) FUNCTION · src
∀ :RT :T :IO :M. (BaseIo :IO) (Threads :RT :T :IO) (MonadIo :M) ⇒ :IO Boolean * List ParkingSet &key (:timeout TimeoutStrategy) → :M UnitParks the current thread in PSETS if SHOULD-PARK? returns True. Will park the thread until woken by an unpark from another thread. Upon an unpark, the thread will resume even if SHOULD-PARK? is False! SHOULD-PARK? is only checked to determine if the thread should park, *not* if it should resume. Can specify a timeout. Concurrent: - WARNING: SHOULD-PARK? must not block, or the thread could be left blocked in a masked state. - Can briefly block while trying to park the thread, if contended.
(UNPARK-SET PSET) FUNCTION · src
∀ :M. MonadIo :M ⇒ ParkingSet → :M UnitAtomically reset PSET, then attempt to unpark all threads parked on the set. Concurrent: - Can briefly block while trying to reset the set or unpark a parked thread
(PARK-IN-SET-IF_) FUNCTION · src
∀ :M. MonadIo :M ⇒ IO Boolean * ParkingSet &key (:timeout TimeoutStrategy) → :M UnitParks the current thread in PSET if SHOULD-PARK? returns True. Will park the thread until woken by an unpark from another thread. Upon an unpark, the thread will resume even if SHOULD-PARK? is False! SHOULD-PARK? is only checked to determine if the thread should park, *not* if it should resume. Can specify a timeout. Concurrent: - WARNING: SHOULD-PARK? must not block, or the thread could be left blocked in a masked state. - Can briefly block while trying to park the thread, if contended.
(PARK-IN-SETS-IF_) FUNCTION · src
∀ :M. MonadIo :M ⇒ IO Boolean * List ParkingSet &key (:timeout TimeoutStrategy) → :M UnitParks the current thread in PSETS if SHOULD-PARK? returns True. Will park the thread until woken by an unpark from another thread. Upon an unpark, the thread will resume even if SHOULD-PARK? is False! SHOULD-PARK? is only checked to determine if the thread should park, *not* if it should resume. Can specify a timeout. Concurrent: - WARNING: SHOULD-PARK? must not block, or the thread could be left blocked in a masked state. - Can briefly block while trying to park the thread, if contended.
Package IO/CONC/SCHEDULER
Classes
Scheduler CLASS · src
Scheduler :SA Scheduler distributes work from producer threads to worker threads. Generally, the Scheduler is allowed to completely control the worker threads: it can sleep, block, spin, etc., as dictated by the Scheduler algorithm. However, it must give producer threads the choice of how to respond to the state of the Scheduler. For example, if the Scheduler is bounded and its internal queue is full, the producer thread chooses whether to block or fail based on its choice of which submit function to call. The main purpose of a Scheduler is to pass into a WorkerPool to configure its scheduling algorithm. A Scheduler could have uses in other contexts. A Scheduler may be bounded or unbounded and still satisfy the Scheduler interface. For unbounded schedulers, `submit` will never block and `try-submit` will always succeed. Threads asking for work will submit a thread-index to the scheduler. The Scheduler can choose to use this, particularly if it maintains a separate queue for each thread, or choose to ignore it, if it only uses a single queue for all threads. Thread index values should be 0-indexed, from [0, n-threads).
Methods:SUBMIT :: Threads :RT :T :M ⇒ :A * :S :A → :M Unit
Submit a new item to the Scheduler. Concurrent: - Blocks if the Scheduler is full. Only bounded Schedulers will ever be full.SUBMIT-WITH :: Threads :RT :T :M ⇒ :A * TimeoutStrategy * :S :A → :M Unit
Submit a new item to the Scheduler. Concurrent: - Blocks if the Scheduler is full, possibly timing out based on STRATEGY. Only bounded Schedulers will ever be full.TRY-SUBMIT :: Threads :RT :T :M ⇒ :A * :S :A → :M Boolean
Attempt to submit a new item to the Scheduler. Returns `True` if the item was added, or `False` if the Scheduler was full. Only bounded Schedulers can be full.TAKE-ITEM :: Threads :RT :T :M ⇒ UFix * :S :A → :M :A
Take the next item from the Scheduler for the given thread. Concurrent: - May block, sleep, spin, or do anything else to the requesting thread, except (1) leave it masked after returning, or (2) stop the thread.
Instances
Package IO/CONC/FUTURE
Structs
Future #<COALTON-IMPL/TYPECHECKER/TYPES:TYVAR :A> STRUCT · src
Container for an value that will eventually be returned by a concurrent operation. Concurrent: - Future's `(Concurrent Future :a)` instance defers to the underlying thread, so it takes on masking semantics of the underyling thread's `Concurrent` instance.
Instances
Concurrent (Future :A) :ARuntimeRepr (Future :|0|)
Values
(FORK-FUTURE TASK) FUNCTION · src
∀ :I :RT :T :R :A :M. (Exceptions :R) (LiftTo :R :M) (UnliftIo :R :I) (Threads :RT :T :R) (Threads :RT :T :M) ⇒ :R :A → :M (Future :A)Spawn a new future, which will run and eventually return the result from TASK. The future is guaranteed to only ever run at most once, when the produced :m is run.
(TRY-READ-FUTURE FUTURE) FUNCTION · src
∀ :RT :T :A :M. (Threads :RT :T :M) (Exceptions :M) ⇒ Future :A → :M (Optional :A)Try to read the current value from FUTURE, returning NONE if it is not available. Raises any exceptions in the awaiting thread that were raised in the future thread.
(FORK-FUTURE_) FUNCTION · src
∀ :A :M. (Threads IoRuntime IoThread :M) (LiftTo IO :M) ⇒ IO :A → :M (Future :A)Spawn a new future, which will run and eventually return the result from TASK. The future is guaranteed to only ever run at most once, when the produced :m is run.
Macros
DO-FORK-FUTURE (&BODY BODY) MACRO
Spawn a new future, which will run and eventually return the result from TASK. The future is guaranteed to only ever run at most once, when the produced :m is run.
DO-FORK-FUTURE_ (&BODY BODY) MACRO
Package IO/CONC/ATOMIC
Types
AtVar TYPE · src
A container that can be read and modified atomically.
Instances
RuntimeRepr (AtVar :|0|)
Values
(MODIFY ATM F) FUNCTION · src
∀ :A :M. (MonadIo :M) (Exceptions :M) ⇒ AtVar :A * (:A → :A) → :M :AAtomically modify `atm` by applying `f` and return the new value. `f` must be a pure function. If `f` throws an error, `atm` will be unchanged and the error will be handleable via `Exceptions`. Concurrent: - WARNING: `f` will be retried each time the calling thread loses the race to update `atm`, so `f` must be pure.
(MODIFY-SWAP ATM F) FUNCTION · src
∀ :A :M. MonadIo :M ⇒ AtVar :A * (:A → :A) → :M :AAtomically modify `atm` by applying `f` and return the old value. `f` must be a pure function. If `f` throws an error, `atm` will be unchanged and the error will be handleable via `Exceptions`. Concurrent: - WARNING: `f` will be retried each time the calling thread loses the race to update `atm`, so `f` must be pure.
(NEW-AT-VAR VAL) FUNCTION · src
∀ :A :M. MonadIo :M ⇒ :A → :M (AtVar :A)Create a new AtVar containing `val`.
(POP ATM) FUNCTION · src
∀ :A :M. MonadIo :M ⇒ AtVar (List :A) → :M (Optional :A)Atomically pop and retrieve the head of an atomic list.
(PUSH ATM ELT) FUNCTION · src
∀ :A :M. MonadIo :M ⇒ AtVar (List :A) * :A → :M (List :A)Atomically push a value onto an atomic list. Returns the new list.
(READ ATM) FUNCTION · src
∀ :A :M. MonadIo :M ⇒ AtVar :A → :M :AAtomically read the value from `atm`.
(WRITE ATM VAL) FUNCTION · src
∀ :A :M. MonadIo :M ⇒ AtVar :A * :A → :M UnitAtomically write a new value to `atm`.
Package IO/CONC/MVAR
Structs
MChan #<COALTON-IMPL/TYPECHECKER/TYPES:TYVAR :A> STRUCT · src
A synchronized FIFO queue to pass data directionally between threads.
Instances
RuntimeRepr (MChan :|0|)
MVar #<COALTON-IMPL/TYPECHECKER/TYPES:TYVAR :A> STRUCT · src
A synchronized container that can be empty or hold an :a. All critical MVar operations are masked. However, irresponsible stopping could still cause deadlocks and other race conditions.
Instances
RuntimeRepr (MVar :|0|)
Values
(IS-EMPTY-MVAR MVAR) FUNCTION · src
∀ :RT :T :A :M. Threads :RT :T :M ⇒ MVar :A → :M BooleanReturn True if the MVar is currently empty.
NEW-EMPTY-CHAN VALUE · src
∀ :RT :T :M :A. Threads :RT :T :M ⇒ :M (MChan :A)Create a new empty channel.
NEW-EMPTY-MVAR VALUE · src
∀ :RT :T :M :A. Threads :RT :T :M ⇒ :M (MVar :A)Create a new empty MVar.
(NEW-MVAR VAL) FUNCTION · src
∀ :RT :T :A :M. Threads :RT :T :M ⇒ :A → :M (MVar :A)Create a new MVar containing VAL.
(POP-CHAN CHAN) FUNCTION · src
∀ :RT :T :A :M. Threads :RT :T :M ⇒ MChan :A &key (:timeout TimeoutStrategy) → :M :APop the front value in CHAN. Blocks while CHAN is empty. Can specify a timeout.
(PUSH-CHAN CHAN VAL) FUNCTION · src
∀ :RT :T :A :M. Threads :RT :T :M ⇒ MChan :A * :A → :M UnitPush VAL onto CHAN.
(PUT-MVAR MVAR VAL) FUNCTION · src
∀ :RT :T :A :M. Threads :RT :T :M ⇒ MVar :A * :A &key (:timeout TimeoutStrategy) → :M UnitFill an empty MVar, blocking until it becomes empty. Can specify a timeout. Concurrent: - Blocks while the MVar is full - Writers (including `put-mvar`) are woken individual on succesful takes in order of acquisition - On succesful put, blocking read-consumers are woken individually in order of acquisition - On succesful put, all blocking read-non-consumers are woken simultaneously. New data is handed directly to woken read-non-consumers so they don't contend on the MVar.
(READ-MVAR MVAR) FUNCTION · src
∀ :RT :T :A :M. Threads :RT :T :M ⇒ MVar :A &key (:timeout TimeoutStrategy) → :M :ARead a value from an MVar, blocking until one is available. Does not consume value. Can specify a timeout. Concurrent: - Blocks while the MVar is empty - Blocking read-non-consumers (including `read-mvar`) are woken simultaneously on succesful put. Data is handed directly to woken readers, which don't contend on mvar.
(SWAP-MVAR MVAR NEW-VAL) FUNCTION · src
∀ :RT :T :A :M. Threads :RT :T :M ⇒ MVar :A * :A &key (:timeout TimeoutStrategy) → :M :AAtomically replace the value in an MVar and return the old value. Can specify an optional timeout. Concurrent: - Blocks while the MVar is empty - Wakes the next blocking read-consumer when `swap-mvar` completes
(TAKE-MVAR MVAR) FUNCTION · src
∀ :RT :T :A :M. Threads :RT :T :M ⇒ MVar :A &key (:timeout TimeoutStrategy) → :M :ATake a value from an MVar, blocking until one is available. Can specify a timeout. Concurrent: - Blocks while the MVar is empty - Read-consumers (including `take-mvar`) are woken individual on succesful puts, in order of acquisition - On succesful take, one blocking writer is woken in order of acquisition
(TAKE-MVAR-MASKED MVAR) FUNCTION · src
∀ :RT :T :A :M. Threads :RT :T :M ⇒ MVar :A &key (:timeout TimeoutStrategy) → :M :ATake a value from an MVar, blocking until one is available. Can specify a timeout. Concurrent: - WARNING: Leaves the thread masked when returns to protect caller's critical regions based on consuming and restoring MVar to a valid state. See MChan for an example. - Blocks while the MVar is empty - Read-consumers (including `take-mvar-masked`) are woken individual on succesfull puts, in order of acquisition - On succesful take, one blocking writer is woken in order of acquisition
(TRY-POP-CHAN CHAN) FUNCTION · src
∀ :RT :T :A :M. Threads :RT :T :M ⇒ MChan :A → :M (Optional :A)Attempt to pop the front value in CHAN. Does not block.
(TRY-PUT-MVAR MVAR VAL) FUNCTION · src
∀ :RT :T :A :M. Threads :RT :T :M ⇒ MVar :A * :A → :M BooleanAttempt to immediately put a value into an MVar. Returns True if succeeded. Concurrent: - Can briefly block while waiting to fill the MVar, if contended - On succesful put, blocking read-consumers are woken individually in order of acquisition - On succesful put, all blocking read-non-consumers are woken simultaneously. New data is handed directly to woken read-non-consumers so they don't contend on the MVar.
(TRY-READ-MVAR MVAR) FUNCTION · src
∀ :RT :T :A :M. Threads :RT :T :M ⇒ MVar :A → :M (Optional :A)Attempt to immediately read a value from an MVar. Returns None if empty.
(TRY-TAKE-MVAR MVAR) FUNCTION · src
∀ :RT :T :A :M. Threads :RT :T :M ⇒ MVar :A → :M (Optional :A)Attempt to immediately take a value from an MVar. Returns None if empty. Concurrent: - Can briefly block while waiting to empty the MVar, if contended - On succesful take, one blocking writer is woken in order of acquisition
(TRY-TAKE-MVAR-MASKED MVAR) FUNCTION · src
∀ :RT :T :A :M. Threads :RT :T :M ⇒ MVar :A → :M (Optional :A)Attempt to immediately take a value from an MVar. Returns None if empty. Concurrent: - WARNING: Leaves the thread masked when returns to protect caller's critical regions based on consuming and restoring MVar to a valid state. See MChan for an example. - Can briefly block while waiting to empty the MVar, if contended - On succesful take, one blocking writer is woken in order of acquisition
(WITH-MVAR MVAR OP) FUNCTION · src
∀ :I :RT :T :A :R :B :M. (UnliftIo :R :I) (LiftTo :R :M) (Threads :RT :T :I) ⇒ MVar :A * (:A → :R :B) → :M :BRun an operation with the value from an MVar, blocking until one is available. Restore the MVar value and return the result of the operation. WARNING: If the computation raises an unhandled exception or is stopped, leaves the MVar empty! Concurrent: - WARNING: Does not mask during the computation. To ensure completion, caller must mask - Blocks while the MVar is empty - Inherits notify semantics from `put-mvar` - Does not leave the MVar locked during the computation. Thus, other threads can put the MVar during the computation and force `with-mvar` to block until empty.
(WITH-MVAR_) FUNCTION · src
∀ :A :B :M. (Threads IoRuntime IoThread :M) (LiftTo IO :M) ⇒ MVar :A * (:A → IO :B) → :M :BRun an operation with the value from an MVar, blocking until one is available. Restore the MVar value and return the result of the operation. WARNING: If the computation raises an unhandled exception or is stopped, leaves the MVar empty! Concurrent: - WARNING: Does not mask during the computation. To ensure completion, caller must mask - Blocks while the MVar is empty - Inherits notify semantics from `put-mvar` - Does not leave the MVar locked during the computation. Thus, other threads can put the MVar during the computation and force `with-mvar` to block until empty.
Macros
DO-WITH-MVAR_ ((SYM MVAR) &BODY BODY) MACRO
Run an operation with the value from an MVar, blocking until one is available. Stores the result of the operation in the MVar and returns. WARNING: If the computation raises an unhandled exception or is stopped, leaves the MVar empty! Concurrent: - WARNING: Does not mask during the computation. To ensure completion, caller must mask - Blocks while the MVar is empty - Inherits notify semantics from `put-mvar` - Does not leave the MVar locked during the computation. Thus, other threads can put the MVar during the computation and force `with-mvar` to block until empty.
Package IO/CONC/GROUP
Structs
ConcurrentGroup #<COALTON-IMPL/TYPECHECKER/TYPES:TYVAR :C> #<COALTON-IMPL/TYPECHECKER/TYPES:TYVAR :A> STRUCT · src
Handles masking, stopping, and awaiting a group of Concurrents as a unit. ConcurrentGroup does not pass messages/data. For more structured uses, see WorkerPool. ConcurrentGroup provides the following guarantees: * Masking/unmasking the group is atomic. If another thread attempts to stop the group, it will either stop all of the Concurrents or none of them. * Stopping the group sends the stop signal to all of the enclosed Concurrents. * Awaiting the group blocks until all of the enclosed Concurrents have completed. * Awaiting the group will error if any one of the enclosed Concurrents errored. * Calling unmask-finally on the group runs the callback on each Concurrent separately, not once on the thread calling (unmask-finally). ConcurrentGroup's guarantees are only valid if management of the enclosed Concurrents is done through the group. For example, if one thread tries to mask the group while another thread tries to stop one of the individual Concurrents in the group, then the second thread might stop the individual Concurrent before the first thread has a chance to mask it. Concurrent: - The `(Concurrent ConcurrentGroup :a)' instance masks `stop`, `mask`, `unmask`, and `unmask-finally` to guarantee atomicity of the enclosed Concurrents - `await` is not masked
Instances
Concurrent :C :A ⇒ Concurrent (ConcurrentGroup :C :A) (List :A)RuntimeRepr (ConcurrentGroup :|0| :|1|)
Values
(ENCLOSE-GROUP CONCURRENTS) FUNCTION · src
∀ :RT :T :C :M :A. (Threads :RT :T :M) (Concurrent :C :A) ⇒ List :C → :M (ConcurrentGroup :C :A)Enclose already forked Concurrents in a ConcurrentGroup. Warning: After calling, the enclosed Concurrents should only be managed through the group.
(FORK-GROUP FORK-CONCURRENTS) FUNCTION · src
∀ :RT :T :M :C :A. (Threads :RT :T :M) (Concurrent :C :A) ⇒ List (:M :C) → :M (ConcurrentGroup :C :A)Run a list of IO operations that each forks a Concurrent. Enclose the forked Concurrents in a ConcurrentGroup. Concurrent: - Does not mask the forking operation, so it is possible to partially fork if stopped. To guarantee forking completion, caller should mask the call to `fork-group`.
Package IO/CONC/STM
Types
STM TYPE · src
A transaction that can be run using `run-tx`.
Instances
(Exceptions :IO) (MonadIo :IO) ⇒ Exceptions (STM :IO)Functor :IO ⇒ Functor (STM :IO)Monad :IO ⇒ Applicative (STM :IO)Monad :IO ⇒ Monad (STM :IO)RuntimeRepr (STM :|0| :|1|)
TVar TYPE · src
A Transaction Variable that can be read and modified inside an STM transaction.
Instances
(Eq (Cell :A)) (Eq ParkingSet) ⇒ Eq (TVar :A)RuntimeRepr (TVar :|0|)
Values
(MODIFY-SWAP-TVAR TVAR F) FUNCTION · src
∀ :A :M. MonadIo :M ⇒ TVar :A * (:A → :A) → STM :M :AModify a mutable variable inside an atomic transaction. Returns the old value.
(MODIFY-TVAR TVAR F) FUNCTION · src
∀ :A :M. MonadIo :M ⇒ TVar :A * (:A → :A) → STM :M :AModify a mutable variable inside an atomic transaction. Returns the new value.
(NEW-TVAR VAL) FUNCTION · src
∀ :A :M. MonadIo :M ⇒ :A → :M (TVar :A)Create a mutable variable that can be used inside an atomic transaction.
(OR-ELSE TX-A TX-B) FUNCTION · src
∀ :M :A. MonadIo :M ⇒ STM :M :A * STM :M :A → STM :M :ARun TX-A. If it signals a retry, run TX-b. If both transactions signal a retry, then the entire transaction retries.
(READ-TVAR TVAR) FUNCTION · src
∀ :A :M. MonadIo :M ⇒ TVar :A → STM :M :ARead a mutable variable inside an atomic transaction.
RETRY VALUE · src
∀ :M :A. MonadIo :M ⇒ STM :M :ARetry the current operation because the observed state is invalid. Waits for a write transaction to commit somewhere else, and then tries this transaction again. This is useful if the transaction needs to wait for other threads to update the data before it can continue. For example, if the transaction reads from a (TVar Queue) and the queue is empty, it must wait until another thread pushes onto the queue before it can continue. Concurrent: - When the transaction runs, executing retry will abort the transaction and sleep the thread. The thread will sleep until any relevant write transaction commits to the STM, when the retrying thread will wake and retry its transaction. A write transaction only triggers a retry if it writes to a TVar that was read before `retry` was called.
(RETRY-WITH STRATEGY) FUNCTION · src
∀ :M :A. MonadIo :M ⇒ TimeoutStrategy → STM :M :ARetry the current operation because the observed state is invalid. Waits for a write transaction to commit somewhere else, and then tries this transaction again. This is useful if the transaction needs to wait for other threads to update the data before it can continue. For example, if the transaction reads from a (TVar Queue) and the queue is empty, it must wait until another thread pushes onto the queue before it can continue. Concurrent: - When the transaction runs, executing retry will abort the transaction and sleep the thread. The thread will sleep until any relevant write transaction commits to the STM, when the retrying thread will wake and retry its transaction. A write transaction only triggers a retry if it writes to a TVar that was read before `retry` was called. - Will timeout depending on strategy.
(RUN-TX TX) FUNCTION · src
∀ :RT :T :M :A. (Threads :RT :T :M) (Exceptions :M) ⇒ STM :M :A → :M :ARun an atomic transaction. If the transaction raises an exception, the transaction is aborted and the exception is re-raised. WARNING: The STM can abort and re-run the transaction repeatedly, until it completes with a consistent snapshot of the data. Therefore, TX must be pure.
(SWAP-TVAR TVAR NEW-VAL) FUNCTION · src
∀ :A :M. MonadIo :M ⇒ TVar :A * :A → STM :M :ASwap the value of a mutable variable inside an atomic transaction. Returns the old value.
(WRITE-TVAR TVAR VAL) FUNCTION · src
∀ :A :M. MonadIo :M ⇒ TVar :A * :A → STM :M UnitWrite to a mutable variable inside an atomic transaction.
Macros
DO-RUN-TX (&BODY BODY) MACRO
Run an atomic transaction. If the transaction raises an exception, the transaction is aborted and the exception is re-raised. WARNING: The STM can abort and re-run the transaction repeatedly, until it completes with a consistent snapshot of the data. Therefore, TX must be pure.
Package IO/CONC/MCHAN-SCHEDULER
Types
MChanScheduler TYPE · src
An MChanScheduler uses a single MChan internally to manage tasks. Producers submit tasks onto the end of the MChan. Worker threads pop items, one-by-one, from the front of the MChan. MChanScheduler is unbounded.
Instances
Package IO/CONC/WORKER-POOL
Structs
WorkerPool #<COALTON-IMPL/TYPECHECKER/TYPES:TYVAR :S> #<COALTON-IMPL/TYPECHECKER/TYPES:TYVAR :I> #<COALTON-IMPL/TYPECHECKER/TYPES:TYVAR :T> STRUCT · src
A pool of worker threads that execute jobs submitted to the pool.
Instances
(Concurrent (ConcurrentGroup :T Unit) (List Unit)) (Scheduler :S) ⇒ Concurrent (WorkerPool :S :I :T) UnitRuntimeRepr (WorkerPool :|0| :|1| :|2|)
Values
(NEW-WORKER-POOL N-THREADS SCHEDULER) FUNCTION · src
∀ :RT :S :I :M :T. (Threads :RT :T :M) (UnliftIo :I :I) (Threads :RT :T :I) (Exceptions :I) (Exceptions :M) (Concurrent :T Unit) (LiftIo :I :M) (Scheduler :S) ⇒ UFix * :S (Optional (:I Unit)) → :M (WorkerPool :S :I :T)Create a new worker pool. Automatically forks N-THREADS worker threads.
(REQUEST-SHUTDOWN POOL) FUNCTION · src
∀ :RT :S :I :T :M. (Threads :RT :T :M) (Exceptions :M) (Scheduler :S) ⇒ WorkerPool :S :I :T → :M UnitRequest a shutdown. The threads in the pool will shutdown when all of the jobs already in the queue are completed. To immediately stop the threads, use `stop`.
(SUBMIT-JOB POOL JOB) FUNCTION · src
∀ :RT :S :I :T :R :A :M. (UnliftIo :R :I) (LiftTo :R :M) (Threads :RT :T :I) (Exceptions :I) (Scheduler :S) ⇒ WorkerPool :S :I :T * :R :A → :M UnitSubmit a job to the worker pool. Any jobs submitted after a shutdown request will be ignored. Concurrent: - If the pool's scheduler is backed by a bounded data structure, then this can block while the scheduler is full.
(NEW-WORKER-POOL_) FUNCTION · src
∀ :S :M. (Threads IoRuntime IoThread :M) (Exceptions :M) (LiftIo IO :M) (Scheduler :S) ⇒ UFix * :S (Optional (IO Unit)) → :M (WorkerPool :S IO IoThread)(SUBMIT-JOB_) FUNCTION · src
∀ :S :A :M. (Threads IoRuntime IoThread :M) (LiftTo IO :M) (Scheduler :S) ⇒ WorkerPool :S IO IoThread * IO :A → :M UnitMacros
DO-SUBMIT-JOB-WITH (STRATEGY POOL &BODY BODY) MACRO
DO-SUBMIT-JOB (POOL &BODY BODY) MACRO
DO-SUBMIT-JOB_ (POOL &BODY BODY) MACRO
DO-SUBMIT-JOB-WITH_ (STRATEGY POOL &BODY BODY) MACRO
Package IO/CONC/RING-BUFFER
Types
RingBufferScheduler TYPE · src
A RingBufferScheduler uses a single RingBuffer internally to manage tasks. MChanScheduler is bounded.
Instances
SchedulerError TYPE · src
Instances
Structs
RingBuffer #<COALTON-IMPL/TYPECHECKER/TYPES:TYVAR :A> STRUCT · src
A bounded FIFO Multi-Producer, Multi-Consumer Queue implemented as a RingBuffer.
Instances
RuntimeRepr (RingBuffer :|0|)
Values
(DEQUEUE BUFFER) FUNCTION · src
∀ :RT :T :A :M. Threads :RT :T :M ⇒ RingBuffer :A &key (:timeout TimeoutStrategy) → :M :APop an element from BUFFER. Can specify a timeout. Concurrent: - Can block briefly while acquiring lock on buffer. - If empty, blocks until BUFFER is not empty, possibly timing out based on TIMEOUT.
(ENQUEUE ELT BUFFER) FUNCTION · src
∀ :RT :T :A :M. Threads :RT :T :M ⇒ :A * RingBuffer :A &key (:timeout TimeoutStrategy) → :M UnitAdd ELT to BUFFER. Can specify a timeout. Concurrent: - Can block acquiring lock on buffer. - If full, blocks until BUFFER is not full, possibly timing out based on TIMEOUT.
(NEW-RING-BUFFER CAPACITY) FUNCTION · src
∀ :RT :T :M :A. Threads :RT :T :M ⇒ UFix → :M (RingBuffer :A)Create a new ring buffer with the given capacity.
(TRY-ENQUEUE ELT BUFFER) FUNCTION · src
∀ :RT :T :A :M. Threads :RT :T :M ⇒ :A * RingBuffer :A → :M BooleanAttempt to add ELT to BUFFER. Returns True if equeue succeeded, False otherwise. Concurrent: Can block acquiring lock on buffer.
(NEW-RING-BUFFER-SCHEDULER CAPACITY) FUNCTION · src
∀ :RT :T :M :A. (Threads :RT :T :M) (Exceptions :M) ⇒ UFix → :M (RingBufferScheduler :A)Package IO/IO-ALL
Package IO/STUBS/TERM
Values
(RUN-TERM-STUB STUB-OP READ-LINE-INPUTS) FUNCTION · src
∀ :A. FreeT TermStubF Identity :A * List String → Tuple (List String) :A(RUN-TERM-STUBM OPM READ-LINE-INPUTS) FUNCTION · src
∀ :M :A. Monad :M ⇒ FreeT TermStubF :M :A * List String → :M (Tuple (List String) :A)