ForkJoin::ExecutionContext
Inherits Fiber::ExecutionContext < Reference < Object
A work-first execution context inspired by Java's ForkJoinPool and Cilk.
Constructors
Instance methods
:nodoc:
Enqueues a fiber to be resumed inside the execution context. Implementations may check if self is the current context and assume a local scheduler enqueue.
May be called from any ExecutionContext (i.e. must be thread-safe). May also be called from bare threads (outside of an ExecutionContext).
Enqueues a fiber from outside the context. Must be thread-safe.
This deliberately does not reject fibers after shutdown. The runtime also
uses this method to re-enqueue a fiber whose blocking syscall returned
after the monitor detached its thread, which can happen after this context
has been shut down. Rejecting that path would raise inside Scheduler#syscall,
skip the thread's check-in, and leave the thread without a scheduler, so its
next Fiber.suspend would crash the process. New work is rejected at the
#spawn boundary instead, before the fiber is created.
Appends a String representation of this object which includes its class name, its object address and the values of all instance variables.
class Person
def initialize(@name : String, @age : Int32)
end
end
Person.new("John", 32).inspect # => #<Person:0x10fd31f20 @name="John", @age=32>
Stops every scheduler cooperatively. Must be called from outside the context (a fiber of this context raises instead of waiting on itself).
With drain: false (the default) this does not run or cancel queued work:
application fibers must complete before the call, or whatever is still
queued is dropped. Once it returns, external #spawn calls raise and the
schedulers' threads are back in the runtime pool. A fiber still suspended
(on a channel, a timer, or a marked blocking syscall) is not waited for:
its thread returns to the pool when the syscall completes and the fiber
itself is dropped.
With drain: true the context first runs every runnable fiber to
completion: queued and injected work, plus event-loop events that become
ready while draining. Schedulers stop only once the whole context is
observed quiescent (no scheduler running and every runnable source empty).
Fibers blocked on channels, long timers, or I/O are still not waited for —
drain is bounded, it never blocks on a suspended fiber. Work that other
contexts keep submitting during the drain extends it.
Returns whether #shutdown has been called (or is in progress). After
shutdown, external #spawn calls raise RuntimeError; fibers that were
still suspended when shutdown ran are not drained and will not be resumed.
Creates a new fiber then enqueues it to the execution context.
May be called from any ExecutionContext (i.e. must be thread-safe).
:nodoc:
Legacy support for the same_thread argument. Each execution context may
decide to support it or not (e.g. a single threaded context can accept it).
Appends a short String representation of this object which includes its class name and its object address.
class Person
def initialize(@name : String, @age : Int32)
end
end
Person.new("John", 32).to_s # => #<Person:0x10a199f20>
Waits for a scheduler to stop and detach without busy-spinning. The
condition variable is already broadcast by wake_scheduler(all: true)
and by the shutdown wakeups, so a timed wait is enough.