waiting for a message. When tBroadcastTask executes, it sends one message to the message queue, resulting in all three waiting tasks exiting the blocked state.
Note that not all message queue implementations might support the broadcasting facility. Refer to the RTOS manual to see what types of message-queue-management services and operations are supported.
7.8 Points to Remember
Some points to remember include the following:
· Message queues are buffer-like kernel objects used for data communication and synchronization between two tasks or between an ISR and a task.
· Message queues have an associated message queue control block (QCB), a name, a unique ID, memory buffers, a message queue length, a maximum message length, and one or more task-waiting lists.
· The beginning and end of message queues are called the head and tail, respectively; each buffer that can hold one message is called a message-queue element.
· Message queues are empty when created, full when all message queue elements contain messages, and not empty when some elements are still available for holding new messages.
· Sending messages to full message queues can cause the sending task to block, and receiving messages from an empty message queue can cause a receiving task to block
· Tasks can send to and receive from message queues without blocking, via blocking with a timeout, or via blocking forever. An ISR can only send messages without blocking.
· The task-waiting list associated with a message-queue can release tasks (unblock them) in FIFO or priority-based order.When messages are sent from one task to another, the message is typically copied twice: once from the sending task’s memory area to the message queue’s and a second time from the message queue’s memory area to the task’s.
· The data itself can either be sent as the message or as a pointer to the data as the message. The first case is better suited for smaller messages, and the latter case is better suited for large messages.
· Common message-queue operations include creating and deleting message queues, sending to and receiving from message queues, and obtaining message queue information.
· Urgent messages are inserted at the head of the queue if urgent messages are supported by the message-queue implementation.
· Some common ways to use message queues for data based communication include non-interlocked and interlocked queues providing one-way or two-way data communication.
Chapter 8: Other Kernel Objects
8.1 Introduction
In addition to the key kernel objects, such as tasks, semaphores, and message queues, kernels provide many other important objects as well. Because every kernel is different, the number of objects a given kernel supports can vary from one to another. This chapter explores additional kernel objects common to embedded systems development, although the list presented here is certainly not all-inclusive. Specifically, this chapter focuses on:
· other kernel objects, including pipes, event registers, signals, and condition variables,
· object definitions and general descriptions,
· associated operations, and
· typical applications of each.
8.2 Pipes
![](/pic/1/5/4/2/3/1//pic_50.jpg)
Figure 8.1: A common pipe-unidirectional.
A pipe provides a simple data flow facility so that the reader becomes blocked when the pipe is empty, and the writer becomes blocked when the pipe is full. Typically, a pipe is used to exchange data between a data- producing task and a data-consuming task, as shown in Figure 8.2. It is also permissible to have several writers for the pipe with multiple readers on it.
![](/pic/1/5/4/2/3/1//pic_51.jpg)
Figure 8.2: Common pipe operation.
Note that a pipe is conceptually similar to a message queue but with significant differences. For example, unlike a message queue, a pipe does not store multiple messages. Instead, the data that it stores is not structured, but consists of a stream of bytes. Also, the data in a pipe cannot be prioritized; the data flow is strictly first-in, first-out FIFO. Finally, as is described below, pipes support the powerful select operation, and message queues do not.
8.2.1 Pipe Control Blocks
Pipes can be dynamically created or destroyed. The kernel creates and maintains pipe-specific information in an internal data structure called a
Two task-waiting lists are associated with each pipe, as shown in Figure 8.3. One waiting list keeps track of tasks that are waiting to write into the pipe while it is full; the other keeps track of tasks that are waiting to read from the pipe while it is empty.
![](/pic/1/5/4/2/3/1//pic_52.jpg)
Figure 8.3: Pipe control block.