std1.0.0-beta-7 SafeC docs

std :: sync::thread_bare

Struct std::ThreadSched

#include <std/sync/thread_bare.h> source

struct ThreadSched {
    struct TaskScheduler inner;
    int priority[THREAD_MAX];
}

Fields

underlying round-robin scheduler

§int priority[THREAD_MAX]source

per-thread priority (higher = first)

Methods

§static struct ThreadSched new()source · definition

An empty thread scheduler (all slots empty, no threads running).

§generic<T> Thread spawn(fn int(?&T, int) func, ?&T arg, int priority)source · definition

Spawn a thread running func(arg, resume_point) (same protocol as TaskScheduler::spawn). priority >= 0; higher values run earlier in each tick. Returns the Thread id (>= 0) or THREAD_NONE if the table is full.

§int tick()source · definition

Run one scheduling pass: threads are served in descending priority order. Returns the number of still-active threads.

§void run_all()source · definition

Run until all threads complete.

§int is_active(Thread t) constsource · definition

Return 1 if thread t is still active (READY or RUNNING), 0 if DONE.

§void join_thread(Thread t)source · definition

Cooperative join: calls tick() until thread t is done.

§int active_count() constsource · definition

Return number of active (non-DONE) threads.