 Hello, Myself Ravendra Chauhan, Assistant Professor, Department of Electronics Engineering, World Change Institute of Technology, Solabor. In this session, we will discuss how the different tasks in RTOS can be managed. It is RTOS task management, the learning outcome. At the end of this session, student will be able to elaborate the task synchronization. Student can describe the different mechanisms for inter-task communication. Outline of this session, first the single tasking versus multi-tasking. Then review of task, task scheduler and dispatcher. And then we will see the different mechanisms available for inter-task communication. Basically RTOS is the real-time operating system which is a multi-tasking operating system and it is mainly designed for real-time applications. Now, what is single-tasking and the multi-tasking? Now, when a single program is allowed to run at a time, the system is grouped under a single tasking operating system. Means only one program can run at the same time. While in multi-tasking, the operating system allows to execute the multiple programs or the multiple tasks at one time. That's why it is classified as the multi-tasking operating system. Now, recall the concept of task in RTOS. Now, what is the RTOS task? So, the software is decomposed into small, schedulable and sequential program units known as task. Means the any software can have the number of defined tasks. So, in real-time context, the task is the basic unit of execution. Task is governed by three time critical properties. The release time, deadline and execution time. Release time means when at what time task should be ready. The deadline means the task has to complete within that particular defined time and execution time, which the task is taken to complete the execution. So, release time means the time at which the task can be executed. Deadline is the point in time by which the task must complete and execution time denotes the time the task takes to execute. Now, the task scheduler. The scheduler keeps the records of the state of each task and selects one which are ready to execute. So, task scheduler selects only one task at the same time. So, task scheduler allocates the CPU to selected task. A scheduler also helps to maximize the CPU utilization among different tasks in multitasking program and to minimize the waiting time. There are generally two types of scheduler, non-preemptive and priority-based preemptive scheduler. Now, see what the non-preemptive scheduling. In non-preemptive scheduling, consider the example shown in figure one where the four tasks have shown and task one and task three is having the higher priority than the task two and task four. So, the scheduler first selects the higher priority task that is task one. Then it will execute the task one and task one will complete the execution at time t1. Then scheduler will select the task two and the task two will get execute. After completion of the task two, the scheduler will selects the task three and so on. But suppose while executing the task two, task three is ready for the execution where the task three is having the higher priority than task two. But in non-preemptive scheduling, to give the control to the task three depends on the task two. So, task two has voluntarily give the control to the task three. Means it is not mandatory for the task two to release the resources for the task three. Now, in priority-based preemptive scheduling, consider the example shown in figure two where the scheduler has selected the first task that is task one. And task one is completed at time t1. Then scheduler has selected the task two and the task two is executing. But in mean time, the task three which is having the higher priority and it is ready for the execution. Now, in the preemptive scheduling, the task two has to stop and gives the control to the higher priority task that is task three. Then higher priority task three will get execute at time t3. And then the task two will have the control and it will execute the remaining part. And after completion of the task two, the scheduler will go for the task four. Now, task dispatcher. The dispatcher gives the control of the CPU to the task selected by the scheduler by performing context switching and changes the flow of execution. At any time an RTOS is running, the flow of execution passes through one of three areas through the task program code, through an interrupt service routine or through the kernel. Now, the inter-task communication. Now, inter-task communication means the exchange of the required data between the different tasks. So, inter-task communication involves sharing of data among tasks through sharing of memory space, transmission of data and etc. Few of mechanisms available for executing the inter-task communication which includes the CMA4s, mailboxes, message queues, pipes. So, first we will see what the CMA4 is. So, CMA4 is a kernel object used for both resource synchronization and task synchronization. And CMA4 is like a key. Now, suppose for example, the two persons are there and which both are want to ride the one bike. Now, first the person who is having the key will ride on a bike. After it's ride over then it will he will hand over the key to another person and then the another person can have the ride on the same bike. That means the person who is having the key that person can ride the bike. So, similarly here consider the example shown in figure 3 where the two tasks that is task 1 and tasks 2 are shown. And both these tasks want to use the display to display some information. Now, when task 1 wants to make the use of the display. So, first task 1 will acquire the CMA4 for this display. And once the CMA4 is acquired by the task 1, then task 1 will use the display unit. The task 1 will display the required information. And then after the use of the display the task 1 will release the CMA4 for this display. And then the task 2 may acquire the CMA4 for the display and the task 2 may use the display. Now, the mailboxes. Mailbox is just like a postal mailbox. This task can have a mailbox into which others can post a mail. Now, here the one example shown in figure 4 where the two tasks are shown. That is the task 1 and task 2 and the mailbox is shown. Now, this mailbox is nothing but the shared memory space. The task 1 will write the message into the mailbox. And then the task 2 will read the message from the mailbox. Now, message queues. Message queue can be considered as an array of mailboxes. Since the number of mailboxes are cascaded. A message queue is an object used for inter-task communication through which the tasks send or receive the messages placed in a shared memory. A task seeking for a message from an empty queue is blocked either for a duration or until a message is received. The sending and receiving of messages to and from the queue may follow first in first out. Means the first return message will come out first from the queue, last in first out and third one is on priority sequence. Visually a message queue comprises of an associated queue control block which includes the name, unique ID, memory buffers, queue length, maximum message length and one or more task waiting list. A message queue with a length of one is commonly known as a mailbox. Pipes. A pipe is an object that provides simple communication channel used for unstructured data exchange among tasks. A pipe can be opened, closed, returned to and read from. Traditionally, a pipe is a unidirectional data exchange facility. There are two descriptors respectively at each end of the pipe for reading and writing. Data is returned into the pipe as an unstructured byte stream via one descriptor and read from the pipe in the FIPO order from the other. Unlike message queue, a pipe does not store multiple messages but it stores the stream of bytes. References. Embedded Systems by Raj Kamal and a book Embedded Real-Time Systems by Dr. K. V. K. Prasad. Thank you.