Preliminary. ThinkMeta ConcurrentTasks and this documentation are preliminary; everything is subject to change.

Timers

Everything time-related in ConcurrentTasks runs on the core's timer thread. It is off until you enable it.

Enabling timers

EnableTimers starts the timer thread; DisableTimers takes it back. The calls are counted, so a library and the application can both enable timers.

When the last DisableTimers runs, everything still waiting on a timer ends: tasks scheduled to start later exit without running, sleeping tasks wake up, waits with a timeout time out.

Important

Without timers, waits with a timeout wait without limit, SleepTask returns false at once, and tasks cannot be started later. Enable timers before you rely on any of them.

Durations

A Duration counts units of 100 nanoseconds — the unit of Windows timers. Build one with Microseconds, Milliseconds or Seconds; Infinite means no limit.

A duration says how long at least. The timer thread uses a high-resolution waitable timer and fires on a grid of about 0.5 ms on Windows 10 version 1803 and later (otherwise on the system tick, about 15.6 ms), and a task may start running a little later than that.

What timers do

Sleep SleepTask or Task::SleepFor suspend the calling task for a while. Nothing cuts a sleep short.
Wait with a timeout Wait(Duration) on the _s primitives, for example Semaphore_s; underneath SuspendTaskFor.
Start a task later Task::Schedule(priority, delay) or AddTimedTask. Calling it again before the start moves the start.
Cancel a later start Task::CancelSchedule / CancelTimedTask — the task exits without running.
Start now instead Task::ScheduleNow / ScheduleTimedTask.

A task that is started later must provide timer storage (GetTimerData); Task does. The TaskSwap scheduler cannot start tasks later.

See also