Message Queue
Overview
A sample demonstrating the basic usage of Zephyr message queues. A producer thread sends both normal and urgent messages to be retrieved by a consumer thread.
Building and Running
This application can be built and executed on QEMU as follows:
west build -b qemu_x86 samples/kernel/msg_queue
west build -t run
To build for another board target, replace “qemu_x86” above with it.
Sample Output
Every normal message is put at the end of the queue, and they are delivered in FIFO order. Every “urgent” message is put at the beginning of the queue, and it is delivered first as long as no other “urgent” message comes in after it.
In this sample, one producer thread sends 1 urgent message for each 2 normal ones. Note that message C is the first retrieved because it was the last one sent as “urgent”.
[producer] sending: 0
[producer] sending: 1
[producer] sending: A (urgent)
[producer] sending: 2
[producer] sending: 3
[producer] sending: B (urgent)
[producer] sending: 4
[producer] sending: 5
[producer] sending: C (urgent)
[consumer] got sequence: CBA012345
Exit QEMU by pressing CTRL+A x.