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.
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).
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.
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 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.
In the following article, let’s learn about the MCU Development board.
FastBit Embedded Brain Academy Courses
click here:https://fastbitlab.com/course1