FreeRTOS Lecture 6 – What is Multitasking?

  • Post author:
  • Post category:Blog

 

What is Multitasking?

 

 

Multitasking

Let me first give you an analogy of Multitasking.

Let’s consider your typical day, you have got 24 hours, and you try to accomplish various tasks like eating your breakfast, replying to your emails, taking the phone call, taking notes, attending appointments, sleeping, etc. (Figure 1). Your day consists of various tasks, and you try to accomplish as much as possible to keep your day more productive.

 Multitasking
Figure 1. Multitasking example.

 

 

How do you accomplish all these tasks?

One way is you will give a time slice for each activity. Let’s say 20 minutes of a time slice for eating your breakfast, 20 minutes for writing emails, etc. (Figure 2)

And the other way is you can upload the work to your assistants to increase your productivity (Figure 3).

Multitasking
Figure 2. Multitasking with time slicing.

 

Multitasking
Figure 3. Distribution of work among the assistants to increase productivity.

 

Similarly, in multitask able computing, an application may consist of multiple tasks. Each task is supposed to carry out one unique functionality. Let’s say there is an application called a temperature monitor system (Figure 4), and this application has got 3 unique tasks as follows:

Task1: Sensor data reading.

Task2: Updates the display.

Task3: It processes the user inputs like a button press, etc.

This application implements multiple tasks.

 Multitasking
Figure 4. Temperature monitor system.

 

A task means just think like a piece of code, which can run on CPU and execute.

Now you have got one CPU, and you have to do all the above tasks.

How do you run it?

One way is giving a small time slice for each task to run (Figure 5). Let’s say after time slice 1 removes Task1 and makes Task2 run, and so on. To do this, you need a scheduler. A scheduler is one who takes care of scheduling all these tasks onto the CPU to execute. In a multitasking scenario, a scheduler also plays an important role.

Now another way to run all these tasks is to use a multicore processor (Figure 6).

Let’s say you have a processor with four cores. In this case, you don’t need a scheduler to run this application since it has got four cores, and each core can execute one task. So, all these three tasks can execute simultaneously. But in the embedded world, we don’t usually use a processor which has got multiple cores. We usually will have one core and multiple task scenario. To run all these tasks, you will need a scheduler, and it will decide which task should take the CPU next.

Figure 5. Multiple tasks running on a single core processor
Figure 5. Multiple tasks running on a single core processor.

 

Figure 6. Multiple tasks running on a multicore processor.
Figure 6. Multiple tasks running on a multicore processor.

 

Figure 7 shows how the multiple tasks execute on the CPU, which gives the illusion for you that all the tasks are executing simultaneously.

For example, on your desktop, you typically work with lots of software simultaneously. Like you browse the Internet, you listen to music, edit your code using an editor application, use calculators, etc. All these applications will have the respective tasks or processes which share the CPU. But your OS is designed in such a way that it gives you the feeling that all the applications are running simultaneously.

Figure 7. How multiple tasks run on CPU vs. Illusion of human eyes
Figure 7. How multiple tasks run on CPU vs. Illusion of human eyes.

 

Multitasking
Figure 8. Example of multitasking with a single core processor.

In the following article, let’s learn about the MCU Development board.

 

FastBit Embedded Brain Academy Courses

click here:https://fastbitlab.com/course1

FastBitLab

The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.

Leave a Reply