silk.concurrency.scheduler.
The provider protocol that prepares child Fibers and publishes them atomically.
When to use#
Implement Scheduler to supply the task policy for Fiber.forkChild. Application code uses
the Fiber operations and a provider such as silk.concurrency.local_scheduler, not this protocol.
Details#
A fork has two steps:
Scheduler.prepareallocates and prepares one child, but does not publish it. The returnedPendingPublicationowns the complete task submission, the response channel, and the Fiber.Fiber.forkChildregisters that data after the exclusive service dispatch ends, and parks until the driver accepts or rejects the child.
Thus no executable value crosses the service boundary.
Errors#
prepare fails with OutOfMemoryError, or with TaskIdExhaustedError when no task identity
is left.
Gotchas#
A provider must not expose the Fiber before publication succeeds. A publication failure consumes the complete pending value and returns no Fiber.
Import as Scheduler with import silk.concurrency.scheduler { Scheduler }.
Public declarations: 15.
TaskId#
pub struct TaskIdA task identity that is unique within one Scheduler execution.
Details#
A provider reserves identities monotonically and does not reuse them during one execution.
Field value#
pub value: u64The provider-local monotonic identity value.
Implementation Copy for TaskId#
impl Copy for TaskIdImplementation HashKey for TaskId#
impl HashKey for TaskIdOperation equals#
equals: TaskId.taskIdEqualsOperation hash#
hash: TaskId.taskIdHashTaskIdExhaustedError#
pub struct TaskIdExhaustedErrorA typed failure that reports exhaustion of the task identity space.
Implementation Debug for TaskIdExhaustedError#
impl Debug for TaskIdExhaustedErrorOperation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites TaskIdExhaustedError.
PublicationResponse#
pub struct PublicationResponseA response that records whether one prepared child was published or rejected.
Details#
The parent owns this cell while parked. The Scheduler driver changes phase exactly once before
it wakes the parent.
Field phase#
pub phase: ResponseWaiting | ResponsePublished | ResponseRejectedThe current publication decision.
ResponseWaiting#
pub struct ResponseWaitingA publication decision has not been made yet.
ResponsePublished#
pub struct ResponsePublishedThe Scheduler accepted the prepared child for publication.
ResponseRejected#
pub struct ResponseRejectedThe Scheduler rejected and destroyed the prepared child without activation.
NoRequest#
pub struct NoRequestA parent task has no pending publication request.
PendingRequest#
pub struct PendingRequestA parent is parked until the Scheduler processes one publication request.
Field wake#
pub wake: WakeThe Wake consumed after the publication response has been stored.
TaskMailbox#
pub struct TaskMailboxThe parent-facing mailbox for one child publication request.
Field request#
pub request: NoRequest | PendingRequestThe request currently visible to the Scheduler driver.
Field response#
pub response: Shared<PublicationResponse>The response cell written before the request Wake is consumed.
NoSubmission#
pub struct NoSubmissionA submission slot contains no prepared child.
PendingSubmission#
pub struct PendingSubmissionA submission slot owns one complete prepared child.
Field task#
pub task: PreparedTaskThe prepared task moved into the slot before the parent parks.
SubmissionSlot#
pub struct SubmissionSlotThe child-task payload paired with one parent mailbox request.
Field phase#
pub phase: NoSubmission | PendingSubmissionThe currently installed child submission.
PreparedTask#
pub struct PreparedTaskA complete unpublished task that one Scheduler provider prepared.
Details#
The Scheduler driver can put this data into its private task store, or destroy it unchanged. The
Execution stays Initial until a successful publication calls Execution.notifyInitial.
Field identity#
pub identity: TaskIdThe reserved identity of the child.
Field parent#
pub parent: TaskIdThe identity of the structured parent.
Field execution#
pub execution: Intrinsic.Execution<()>The unpublished child Execution.
Field canceller#
pub canceller: CompletionCancellerThe type-erased endpoint used if the task is cancelled.
Field mailbox#
pub mailbox: Shared<TaskMailbox>The child's own publication-request mailbox.
Field submission#
pub submission: Shared<SubmissionSlot>The child's own publication-submission slot.
PendingPublication#
pub struct PendingPublication<A, E>A prepared child Fiber and the canonical data required for atomic publication.
Details#
Fiber.forkChild moves task into parentSubmission, installs a Wake in parentMailbox, and
parks until response reports acceptance or rejection. No executable value crosses the service
boundary.
Field fiber#
pub fiber: Fiber<A, E>The affine result handle returned only after successful publication.
Field parentMailbox#
pub parentMailbox: Shared<TaskMailbox>The mailbox owned by the parent task.
Field parentSubmission#
pub parentSubmission: Shared<SubmissionSlot>The submission slot owned by the parent task.
Field response#
pub response: Shared<PublicationResponse>The response observed after the parent resumes.
Field task#
pub task: PreparedTaskThe complete unpublished child task.
Scheduler#
pub service SchedulerA mutable service that prepares one child task for later atomic publication.
When to use#
Implement it to supply the task policy for Fiber.forkChild. Application code uses the Fiber
operations and a provider such as silk.concurrency.local_scheduler, not this protocol.
Details#
prepare allocates and prepares one child, but does not publish it. Fiber.forkChild registers
the returned PendingPublication after the exclusive service dispatch ends, and parks until
the driver accepts or rejects the child. Thus no executable value crosses the service boundary.
/// Each task receives a distinct owned provider. prepare ends its exclusive provider access
before the caller registers the returned publication data and parks for the response.
Operation prepare#
effect fn prepare<A: 'static, E: 'static>(
child: once Effect<'static;
A
! E
? &mut Scheduler | &mut MonotonicClock
>
) -> PendingPublication<A, E>
! OutOfMemoryError | TaskIdExhaustedError
? &mut SchedulerPrepares one lazy child task and returns its affine publication value.
Details#
The child can require only its owned Scheduler and MonotonicClock providers. Preparation reserves all child endpoints and one task identity before it returns. It does not activate the child.
Implementation Scheduler#
impl SchedulerAssociated function pending#
pub fn pending<A, E>(
fiber: Fiber<A, E>,
parentMailbox: Shared<TaskMailbox>,
parentSubmission: Shared<SubmissionSlot>,
response: Shared<PublicationResponse>,
task: PreparedTask,
) -> PendingPublication<A, E>Creates one canonical pending publication from its prepared data.
When to use#
Use this provider operation after all child task storage and endpoints have been prepared.
Details#
The parent mailbox, submission slot, and response must belong to the calling task. The prepared task remains unpublished and must not have received initial readiness.
Category: Concurrency.
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2.