Embedded Systems & Firmware
In an RTOS, what is the advantage of using a queue (message queue) to pass data from a sensor-reading task to a display task?
- AData passing through a queue is encrypted automatically
- BThe receiver can sleep until data arrives, and differences in speed between sender and receiver are absorbed by the queue
- CUsing a queue makes task priorities unnecessary
Show answer and explanation
Answer: B. The receiver can sleep until data arrives, and differences in speed between sender and receiver are absorbed by the queue
Passing data through a shared variable and flag requires guarding against data races and having the receiver check repeatedly. With an RTOS queue, the sender simply puts data in and the receiver waits in a blocked state without using CPU until data arrives. Because several items can be buffered, no data is lost when the sender is temporarily faster, as long as the queue's capacity is not exceeded.
- A. There is no encryption.
- B. Correct. There is also no need to protect a shared variable manually.
- C. Priorities are still needed.