![]() |
AKOS
v1.0.0
Documentation
|
Inter-thread communication is how AKOS lets one thread send work, data, or signals to another thread.
In the current kernel, communication is built around message queues. Each thread owns a queue, and other threads can post either a pure signal or a signal plus payload. This makes communication explicit, predictable, and easy to combine with the scheduler.
AKOS uses two message types:
Both message types share the same queue infrastructure. The message object stores:
That design lets a thread react to a signal even when no extra data is needed, while still supporting copied payloads for commands, status updates, or small data packets.
AKOS preallocates message objects in a global pool. The pool is initialized by akos_message_init(), and individual messages are returned to the pool with akos_message_free().
Using a fixed pool keeps message allocation predictable:
For dynamic messages, AKOS also allocates a payload buffer from the memory subsystem and copies the payload into that buffer before enqueuing the message.
Each thread has its own FIFO queue. The queue is initialized when the thread is created, and its maximum depth comes from the thread descriptor:
If a thread does not need messaging, its queue size can be zero. If it expects communication, the queue should be sized to match the amount of burst traffic the application can tolerate.
Queue operations are straightforward:
The thread API wraps queue access with scheduler awareness:
These functions do more than enqueue a message. They also check whether the destination thread is blocked waiting for a message. If it is, AKOS moves the thread back to the ready list and may trigger a context switch.
That means message posting can be both communication and synchronization at the same time.
Pure messages are the lightest-weight form of communication.
Use them when:
Examples include:
Dynamic messages carry a copied payload buffer.
Use them when:
Examples include:
Because the payload is copied into the message object, the sender can safely reuse or release the original buffer after posting.
Threads receive messages with:
The behavior is:
When a thread wakes up, it should inspect the message type before reading the payload:
That ownership model is important: once a message has been consumed, the thread must return it to the pool with akos_message_free().
In AKOS, the signal value is the lightweight identifier that tells the receiver what happened. The payload, if present, carries the associated data.
A good mental model is:
The source thread keeps ownership of its original data, while the message object owns the copied payload until the receiver frees the message.
Common communication patterns in AKOS include:
This works especially well for event-driven embedded code because it keeps the thread logic simple and avoids polling loops.