Description
Provides explicit cooperative yield points for CPU-bound task code.
Example:
Flyology.Fairness.Checkpoint (Budget);
Checkpoint
procedure Checkpoint (Budget : in out Yield_Budget)
Yield when Budget's quantum has elapsed. Otherwise return immediately. Lightweight tasks return to their event loop; native tasks perform the normal Ada delay 0.0 scheduling point. Fairness remains cooperative. This is a potentially blocking operation and must not be called from a protected action. The call is not syntactically visible to GNAT's check on protected bodies, so a lightweight caller inside a protected action raises Program_Error at the yield rather than at compile time.
Parameters
- Budget
State owned by the calling task
Raised exceptions
- Program_Error
A lightweight task yields inside a protected action
Configure
procedure Configure (Budget : in out Yield_Budget; Quantum : Ada.Real_Time.Time_Span := Default_Quantum)
Reset Budget and schedule its first eligible yield Quantum from now. Quantum is elapsed wall-clock time. Checkpoint yields at most once after an overrun, then starts a new quantum.
Parameters
- Budget
State owned by the calling task
- Quantum
Positive interval between eligible yields
Default_Quantum
Default_Quantum : constant Ada.Real_Time.Time_Span := Ada.Real_Time.Milliseconds (2);
Default elapsed time between eligible cooperative yields.
Yield_Budget
type Yield_Budget is tagged limited private;
Per-task checkpoint state. A budget is not synchronized and must be used by one task at a time.
Yield_Now
procedure Yield_Now
Perform one cooperative scheduling point using delay 0.0. This is a potentially blocking operation and must not be called from a protected action. The call is not syntactically visible to GNAT's check on protected bodies, so a lightweight caller inside a protected action raises Program_Error rather than being diagnosed at compile time.
Raised exceptions
- Program_Error
A lightweight task yields inside a protected action