Crate thread

Crate thread 

Available on crate feature threading only.
Expand description

Multi-threading for Ariel OS.

Implements a scheduler based on fixed priorities and preemption. Within one priority level, threads are scheduled cooperatively. This means that there is no time slicing that would equally distribute CPU time among same-priority threads. Instead, you need to use yield_same() to explicitly yield to another thread with the same priority. If no thread is ready, the core is prompted to enter deep sleep until a next thread is ready.

Threads should be implemented using the ariel_os_macros::thread proc macro, which takes care of calling the necessary initialization methods and linking the thread function element it into the binary. A ThreadId between 0 and THREAD_COUNT is assigned to each thread in the order in which the threads are declared.

Optionally, the stacksize and a priority between 1 and SCHED_PRIO_LEVELS can be configured. By default, the stack size is 2048 bytes and priority is 1.

§Synchronization

The threading module supports three basic synchronization primitives:

  • Channel: synchronous (blocking) channel for sending data between threads
  • Lock: basic locking object
  • thread_flags: thread-flag implementation for signaling between threads

Modules§

sync
Synchronization primitives.
thread_flags
Thread flags.

Structs§

CoreAffinitycore-affinity
Affinity mask that defines on what cores a thread can be scheduled.
CoreId
ID of a physical core.
RunqueueId
Runqueue number.
ThreadId
Identifier of a thread.

Constants§

CORE_COUNT
Number of processor cores.
IDLE_THREAD_STACK_SIZEmulti-core
Stack size of the idle threads (in bytes).
SCHED_PRIO_LEVELS
The number of possible priority levels.
THREAD_COUNT
The maximum number of concurrent threads that can be created.

Traits§

Arguable
Trait for types that can be used as argument for threads.

Functions§

block_on
Runs a future to completion.
core_id
Returns the id of the CPU that this thread is running on.
create
Low-level function to create a thread that runs func with arg.
create_noarg
Low-level function to create a thread without argument.
current_stack_limits
Returns the current thread’s stack limits (lowest, highest).
current_tid
Returns the ThreadId of the currently active thread.
get_priority
Returns the priority of a thread.
is_valid_tid
Checks if a given ThreadId is valid.
isr_stack_core1_get_limits
Returns the isr stack limits for the second core as (lowest, highest).
park
Suspends/ pauses the current thread’s execution.
set_priority
Changes the priority of a thread.
unpark
Wakes up a thread and adds it to the runqueue.
yield_sameNon-infini-core
“Yields” to another thread with the same priority.