An RTOS uses signals, memory pools and queues to implement inter-process communication (IPC). Threads can't talk directly to each other in an RTOS. The RTOS controls all communications that can occur so threads can pass values or commands through the RTOS. Signals are used to control when other thread can operate i.e. you can block a thread using a signal from another thread. The memory pools and queues are used to pass variable from one thread to another thread.
Signals, Memory Pools and Queues
In an RTOS, signals are used as described above. Memory Pools and Queues are used to send values from one thread to another. The first thing that needs to be set up is the message structure that is to be sent from one thread to another. So any time a message is to be sent it will load into the memory pool in the structure already set. The memory pool(s) and queue(s) should be set up to specify how many of these message structures can be held in the memory pool and how many pointers to the memory pool can be held in the queue. So now that these parameters are set, values can now be sent from one thread to the other. The sending thread must first request a free slot in the memory pool. It can then set up the message with the values it wishes to send before loading it into the allocated memory. The thread is now done so it asks to be taken off the processor. The receiving thread reads the queue for a new address. If there is something in the queue it reads the address of the pointer. This pointer points to the location of the message in the message pool so now the receiving thread has access to the message. It can now read in the message values and the final function in the thread is to free up that location in the memory pool.
mbed RTOS Examples
Examples of signals, memory pools and queues can be found on the mbed developer website below. The next post will show how to use memory pools and queues to send servo control messages to different servo threads.
mbed Examples: https://developer.mbed.org/handbook/RTOS