value class PoolThe Pool class represents the common "thread pool," or more accurately, the common executor.
The static methods of this class are the root of all parallelism in Guardian and are used to enqueue asynchronous tasks.
The underlying executor implementation is configurable at runtime, but the default implementation is a fixed-size
thread pool with a thread count determined by the number of logical cores on the system. As such, the default behavior
of the Pool class is to run tasks in parallel on the system's available threads, but the executor could also be
configured to run tasks serially, as is the case in single-thread debugging mode.
When using the Java backend with the Javalineer implementation of Guards, the executor implementation can be
selected at startup by setting the JAVALINEER_POOL environment variable.
When applicable, the number of threads in the pool can be configured by setting the JAVALINEER_POOL_THREADS
environment variable.
The JAVALINEER_POOL environment variable can be set to one of the following values:
default or fixed: Use the default fixed-size thread pool implementation. This is the default mode when
JAVALINEER_POOL is unset. When using this mode, the JAVALINEER_POOL_THREADS environment
variable can be set to override the default thread count. If this variable is not set, the
default thread count is the number of logical cores on the system.debug: Use a special single-threaded executor which runs tasks in a deterministic, pseudorandom order.
When using this mode, the JAVALINEER_DEBUG_POOL_SEED environment variable can be set to a seed value to
ensure that the same tasks are run in the same order each time. If this variable is not set, the seed is
chosen pseudorandomly.dynamic: Use a cached thread pool implementation, where the thread count is dynamically adjusted based on the
number of tasks currently running.run<T>(task: () -> T) -> Fut<T>Enqueues task to be run asynchronously, returning a future that will be completed with the result of task.
runFut<T>(task: () -> Fut<T>) -> Fut<T>Enqueues task to be run asynchronously, returning a future. When the future returned by task is completed, the
future returned by runFut will be completed with the same result.