
2. TASK CONTROL FUNCTION
B–61863E–1/06
PMC CONTROL SOFTWARE
76
“Example of exclusive control with a mailbox”
Exclusive control can be implemented not only using semaphores but also
using mailboxes.
In this example, suppose that there are two memory blocks temporarily
used by tasks and that these memory blocks are shared by multiple tasks.
The number of entries (the number of memory blocks) is set to two when
a mailbox is created. The start address of each memory block is written
to the mailbox. When a task uses a memory block, it takes out the address
of the memory block by issuing os_read_mbx. After the use of the
memory block, the task writes the address to the mailbox. If data (the start
address of the memory blocks) is not found in the mailbox, the memory
blocks are being used (not empty), and so the task enters the wait state.
With this control mechanism, message passing is possible while
exclusive control is performed.
Mailbox
Task A
Task B
Task C
Pointer
Pointer
Memory
Task D
Block 1
Block 2