DEVELOPMENT EDITION · 769442725406
Language Reference
On this page

Tasks, protected objects, and external devices

Verada provides a restricted Ada/Jorvik-style task model with protected synchronization and analysis of selected concurrency rules. Acceptance and proof of those rules do not imply arbitrary Ada tasking support, a real-time scheduler, fairness, or universal liveness and deadlock freedom.

Tasks and activation

Tasks are declared in library packages and live for the program's supported task lifetime. Vada/Varc support single tasks and task types with supported discriminants; each task object has its own task body execution. The runtime creates threads during elaboration, activates them after library elaboration, and waits for them after main returns.

Vibe supports task-decorated function forms but not every task-type/discriminant/delay-until construction. A Python thread, async coroutine, or dynamically created task is not a substitute for a supported Verada task declaration. Use a mixed package interface where the frontend does not independently represent the required form.

Verada.Tasking.Stop ends the other tasks and the calling one when it is itself a task. A task ends at its next delay or wait, or at its next loop iteration, so one that computes without ever waiting ends too; inside a protected action it ends only once the action is over, so that the object's lock is free for the main subprogram. This is not Ada's abort or a graceful shutdown: a task gets no chance to finish its work or release resources of its own. Design a cooperative completion protocol when the application needs one.

Protected objects

A protected object encapsulates state and operations synchronized by its lock. A protected procedure can update that state, a protected function supplies its permitted read behavior, and an entry waits until its barrier permits execution. Protected types create separate objects with their own state/locks and supported discriminant values.

The runtime implements protected actions with mutex/condition-variable synchronization. An entry whose barrier is closed waits without retaining the lock. Actions that can change barriers notify waiters. A barrier is a condition over the supported protected state, not an arbitrary blocking operation executed while a lock is held.

A protected operation must not reach a potentially blocking operation, directly or through calls. Delays and entry waits are examples; B3020 identifies a violation. Moving a blocking call into a helper does not remove it from the analysis. Vibe protected classes/entries have their own accepted decorator and barrier forms.

Shared state and priorities

Data used by multiple concurrent actors, with a write among the accesses, must follow the protected-state rules. Analysis propagates effects through calls and treats the environment main as another actor. I/O state also matters: printing from several tasks can create a shared effect, rather than being automatically safe because the runtime prints a line at a time. B3019 identifies a detected race.

Task priorities and protected ceilings are checked. A caller's priority cannot exceed the ceiling of a protected object it uses; nested protected use must satisfy the supported ceiling relationship. Default environment/task priority is 48 and the default protected ceiling is 97 in this implementation. Explicit priorities are task/protected controls processed by the tasking frontend, not general aspects applicable to arbitrary declarations.

The runtime runs tasks as POSIX threads under the host's ordinary scheduler; it does not order them by priority. Ceiling relationships are checked properties of the program, not deadline or scheduling guarantees. The runtime's tables of tasks and protected objects grow as the program elaborates them: only memory and the system's limit on threads bound them.

Suspension objects

Ada.Synchronous_Task_Control.Suspension_Object lets one task wait until another sets it true: Set_True, Set_False, Current_State and Suspend_Until_True (which waits until the object is true, then makes it false). A library-level suspension object is synchronised state, shared by tasks without a data race (B3019 does not apply). As Ravenscar and Jorvik require, at most one task waits on each, which Verada checks (B3029), and Suspend_Until_True may wait, so a protected action never calls it (B3020).

Go : Suspension_Object;
...
task body Worker is
begin
   Suspend_Until_True (Go);   --  waits until the main subprogram sets Go
   ...

Interrupt handlers

A protected procedure with Attach_Handler => Interrupt handles that interrupt: the package attaches it as it is elaborated, and once the program is running the procedure is called, under its object's lock, each time the interrupt occurs. On the hosts Verada runs on, an interrupt is a POSIX signal, named in Ada.Interrupts.Names (SIGUSR1, SIGUSR2, SIGHUP, SIGINT, SIGQUIT, SIGALRM, SIGTERM). Interrupt_Priority gives the object's ceiling, as Priority does. A handler runs at the same time as the tasks and the main subprogram, so the data-race analysis counts it as one more of them (B3019).

protected Alarm with Interrupt_Priority => 98 is
   procedure Handle with Attach_Handler => Ada.Interrupts.Names.SIGUSR1;
   entry Wait (Count : out Natural);
private
   Seen : Natural := 0;
   Signalled : Boolean := False;
end Alarm;

Delays and clocks

Relative delay waits at least its duration, to the nanosecond (delay 0.0004 waits 0.4 ms or more), however long Duration allows. Absolute delay waits until the monotonic time supplied by the supported time library. Delaying until an already-past time does not create negative sleep. Clock granularity, thread scheduling, and system load affect actual wakeup; the language does not promise zero jitter or hard deadlines.

Duration has the fixed-point representation described in types, while Ada.Real_Time supplies its declared time/span operations. Use their conversion contracts and units rather than equating every integer time value with seconds. Vibe's supported sleep helpers are not a complete Python async/time API.

A task may have Relative_Deadline => D (RM D.2.6); D is checked as an Ada.Real_Time.Time_Span, and, as with priorities, these hosts schedule no task by it.

Volatile and asynchronous state

An externally accessed object can carry the following properties:

Property Meaning for reasoning and effects
Async_Writers Another agent may write it; distinct reads need not agree
Async_Readers Another agent may observe writes
Effective_Reads A read itself is an observable effect
Effective_Writes A write itself is an observable effect

Volatile or Atomic participates in the implementation's external-object treatment. If no individual properties are given, all four are assumed; explicitly supplied properties select the corresponding subset. These controls do not license arbitrary aliasing with ordinary proved variables or provide a complete atomic memory-order/RMW API. Use protected objects for supported task synchronization rather than inferring a lock-free protocol.

Read an asynchronously written/effectively read value in a non-interfering whole-value context, such as assignment, initialization, a parameter actual, or return. Then use that stable local snapshot in arithmetic. Repeating two reads inside an expression can produce different inputs and is restricted (B3023).

An ordinary function cannot read through a call chain a value that changes independently or has read effects (B3022). Volatile_Function permits the supported special input behavior: calls are treated as potentially distinct values and must also occur in the allowed whole-value contexts. It does not make an arbitrary side-effecting function pure.

External abstract state

Public abstract state can be marked external with selected asynchronous/effect properties and refined to corresponding volatile objects in the body. The public contract then tells clients what the environment can change without exposing the hardware representation. An Abstract_State name alone is not a guarantee that the device obeys the model's range, protocol, or timing assumptions.

Addresses, imports, and overlays

System and System.Storage_Elements provide the supported address type and conversions. X'Address requires an object named directly and the necessary System visibility. An address-bearing object must be declared in a package and be effectively volatile (Volatile or the supported Atomic classification). The address expression must have the accepted constant/address/conversion form; this is not general unchecked pointer arithmetic.

Status : Unsigned_32
  with Volatile, Import, Address => To_Address (16#4000_1000#);

This fragment requires visible Unsigned_32 and storage-element operations. Import suppresses ordinary initialization for the object; it does not prove the mapped address exists, is aligned for the native access, or is safe on the current host.

An imported constant may also have an address without being volatile: read-only memory, such as a calibration table in flash. The prover knows nothing of its values, but that they never change between reads.

Factors : constant Calibration
  with Import, Address => To_Address (16#0800_4000#);

An overlay of another object is permitted only with the required external/volatile classification on that object too. Otherwise an ordinary variable's proved value could be changed through a hidden alias. Address definition clauses feed the same supported mechanism. The obsolete for X use at ... form is separately diagnosed and must not be confused with the supported address aspect.

Excluded concurrency forms

Task entries and rendezvous (accept, select), abort, requeue, dynamically created tasks, synchronized interfaces, parallel loops and coroutines are not part of the language. Use library tasks that communicate through protected objects, entries and suspension objects. The Toolchain Manual describes runtime and platform requirements.