Crate thread
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 threadsLock: basic locking objectthread_flags: thread-flag implementation for signaling between threads
Modules§
- sync
- Synchronization primitives.
- thread_
flags - Thread flags.
Structs§
- Core
Affinity core-affinity - Affinity mask that defines on what cores a thread can be scheduled.
- CoreId
- ID of a physical core.
- Runqueue
Id - Runqueue number.
- Thread
Id - Identifier of a thread.
Constants§
- CORE_
COUNT - Number of processor cores.
- IDLE_
THREAD_ STACK_ SIZE multi-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
funcwitharg. - 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
ThreadIdof the currently active thread. - get_
priority - Returns the priority of a thread.
- is_
valid_ tid - Checks if a given
ThreadIdis 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_
same Non- infini-core - “Yields” to another thread with the same priority.