Passing data through queues by value
Like semaphores and mutexes, queues are among the most widely used structures when using asynchronous tasks. They can be found in nearly every operating system, so it is beneficial to understand how to use them. We’ll look at several different ways of using queues and interacting with them to affect a task’s state.
In the following examples, we’ll learn how to use queues as a means of sending commands to an LED state-machine. First, we’ll examine a very simple use-case, passing a single one-byte value to a queue and operating on it.
Passing one byte by value
The first example-program we’ll be using is mainQueueSimplePassByValue.c
. It has two tasks, and they communicate with each other by using a queue. One task sends items to the queue (sendingTask
), and the other task receives the items (recvTask)
. The queue’s items are uint8_t
values, and each item specifies which LEDs to turn on or off. When...