The purpose of this article is to clarify, or confuse even more, the use of the word multitasking.
The word multitasking means performing several tasks simultaneously. Our brain does multitasking. If you eat dinner watching TV, your eyes process the picture while your ears process the sound. This processing differentiates between the pictures and sounds from the TV and all others around you. Your hand carries food to your mouth, your mouth chews the food, you feel its flavor and its odor, etc., etc. You might also sustain a conversation, or think on an office problem. All this happens simultaneously. Each function is independent of the others. The reason is that our brain has a very large number of processing units.
The first computers I built were not multitasking. They used a seven-segment LED display, like the ones used today in digital meters. These displays require continuous refreshing by the computer. When the computer performed some operation, the display went blank. The reason is that the central processing unit, or microprocessor as was called in that time, cannot do multitasking. A microprocessor, whether a 6502, a 68000 or a Pentium, can perform only one operation at a time.
When the TV-type of display was adapted to the computer, it was very annoying that the display went blank or berserk, when the computer performed a task. The solution was to put two microcomputers, one to handle the display and another to handle the tasks for the user. This is multitasking. This is the way it is today. Once I built a computer with several microprocessors, one for the display, one for the keyboard, others for various tasks, one as the director of an orchestra, telling the others what to do. All computers today are multitasking.
Since today all computers are multitasking, the meaning of the word has changed. Today we understand as multitasking when the computer performs at the same time several tasks for us. This considers the computer as a box. We are not concerned with the internal multitasking. We talk about the box as a whole. Notice that the central processing unit cannot perform multitasking. A computer with only one central processing unit available to the user, cannot do multitasking.
For this reason, the definition of multitasking has changed more. Today we call multitasking when a computer gives us the appearance of doing several things at the same time. Note that we say appearance. There are several ways this can be accomplished. All of them imply that the operating system, or the program, uses the computer for several tasks, one at a time.
Let us clarify this idea. How a computer can give us the appearance of doing several things at the same time? Consider a computer running two programs at the same time. Since the processor can do only one thing at a time, there has to be another program that controls the switching between the two programs. This is the multitasking operating system. Let us assume a simple scenario. Consider the two programs display some text on half of the screen each. Program A moves the cursor with the mouse. Program B moves the cursor with the arrow keys. That is all they do.
One possibility is that the operating system sets program A to run. After one minute, the operating system gains control of the system, sets program B to run. This process continues until we stop it. We will notice that for one minute we control the cursor with the mouse and the arrow keys do nothing. The next minute the situation reverses. Although it is clear we are running the two programs, this will hardly look as a simultaneous operation.
Consider now that we change the operating system. Instead of changing program every minute, we change every second. The operation will look to us smoother, but not yet simultaneous. Consider the next change to the operating system. We change program every tenth of a second. Notice that in one tenth of a second the computer can perform quite a lot of operations. Now the operation will appear to us as simultaneous. It is clear that the operations are not simultaneous, they only appear to us as such. Wherever we touch the mouse one cursor moves. When we press an arrow key the other cursor moves. This is time sharing. We say that the computer use is shared by the two processes.
Since the change to one tenth of a second improved the operation, we change it to one millisecond. That is, we change program every millisecond. When we try the system we find that it does not work. The values of time given here are examples. Other values produce the results explained here with other processors. The reason why the system does not work now is that we have oversimplified the description.
What really happens is that, at some time, the operating system takes over the computer to switch to program A. This includes saving all the registers and parameters from program B and some times, the memory where the program and the data are stored. Then, setting the registers, parameters, and memory to the values for program A. Then the operating system gives control of the processor to program A. But this is not a total control. The operating system must check if it is time to switch to the other program. It is clear, that if we try to switch programs too often, most of the time will be spent switching programs and not doing things.
There is another possibility. Imagine that in our example above, program A tests the mouse. If it has moved, it moves the cursor; then, it returns control to the operating system. The operating system then sets program B. This program tests the arrow keys. If some has been pressed, it moves the cursor; then, it gives control back to the operating system. This switching continues until we stop the process. This is called task switching. It has advantages in that each program is allowed to complete a task. This advantage depends on the tasks. It has disadvantages. Imagine that both operators are idle. The mouse is not moved and the keys are not pressed. The operating system is switching from task to task, doing nothing but changing registers, parameters, and probably memory. The other problem is that the smoothness of the operation depends on how the tasks are defined. Let us elaborate on this point.
It is easier to consider multitasking within a single program. Imagine a word processing program printing a file. It could print the file character by character, waiting for the printer to finish. Only when the file has been totally printed, it returns control to the user. You can imagine a little more intelligent program. Imagine the program looking at the keyboard and, while nothing happens with the keyboard, it sends characters to the printer. When you press a key, it processes it as normal. It will give you the impression that the two tasks are performed simultaneously. The reason is that both tasks, looking at the keyboard and sending a character to the printer, are very fast from our point of view.
Now, let us get a little more complex. Imagine you ask the program to print a file and then you ask it to store the file on disk. Now things become different. Working as above, the program will send one character to the printer and then proceed with accessing the disk. Since the disk operation takes time, you will notice that the printing stops until the disk operation is performed.
The program could be a little more intelligent. It could send one block of data to the disk and one character to the printer, as they are needed. Then, you will consider both operations are performed simultaneously. Naturally, they are not, but they look to you as if they were. The reason is again that the operations are fast from our point of view. Notice that you cannot perform this experiment today because all printers have a microprocessor that receives a large block of characters and prints them as required.
We have been talking about multitasking from the point of view of a program. We can talk from the point of view of the operating system. Every program can be divided in tasks. These tasks can be reading the keyboard, processing a command, storing a sector on disk, sending one character to the printer, sending a picture to the screen, performing some computation, etc. The computer can perform one task for one program, go to the other program and perform one task, etc. In this way, the switching between the programs is much faster and they both seem to run smoother. There will always be situations when it is evident that one program stops working.
Time sharing is the procedure used by advanced operating systems, like UNIX or LINUX, the PC version of UNIX. Most of the other operating systems use task switching. How good is time sharing depends on the time allotted to each process, as we saw above. How good is the task switching depends on how the operating system defines the tasks. Some examples above define the tasks in a very rough fashion. This is the case of the program that defines as one task the whole operation of storing a file on disk or printing a file. A finer task definition, like defining storing a sector as a task, produces better and smoother results.
Notice that saying that an operating system does multitasking does not say anything, unless the procedure for doing it is explained. The same is true with task switching, you need to know how the tasks are defined. This is especially important when you try to compare two different operating systems. This is the reason for most of the confusion today.
Talking about multitasking, let us clarify something. WINDOWS is a multitasking environment. When you open several programs in WINDOWS and reduce them to icons, that is not multitasking. The programs are not running, unless you indicate they should run in the background, which is not the normal case. You need to open the Properties box and set it there. Besides, a program that requires keyboard input, like a game, cannot run in the background.
Another important point to consider is that any method for multitasking requires functions that the operating system must perform before giving control to a program. For example, in a time shared system with several terminals, the system must check all the terminals every so often, whether they are in use or not. The same is true for a task switching system. There is also the problem of what values must be saved when changing from program to program. When OS/2 executes DOS programs, it allots each one 640 K of memory, so it does not have to switch memory when switching programs. Similar problem appears with the other resources. Imagine two programs using a serial port at different baud rates. It is necessary to change the configuration of the port when changing programs. I cannot think of a single reason why anybody will want to do so. Consequently, if you run a single program in any multitasking environment, your program will run slower than if it runs under DOS.
I have a program, SYSCHK, that checks the system. Among a large number of checks, it measures the speed of the computer. There are quite a number of similar programs. I do not know how it measures the speed. In any case, the values are relative numbers. When I run this program under DOS, the speed of my system is somewhat above 100. Running the same program under WINDOWS the result is around 15. Running it under OS/2 the result varies between 15 and 30. Since the program is the same, these numbers give you an idea of the overhead of each system.
Another program I wrote, uses the timer to produce a sequence of notes up and down a scale. I use it as an alarm or to indicate that a long program has ended. The note is controlled by the timer but the length of the note and the space between them are controlled by software. When I run the program under DOS, the length of each note is about one tenth of a second, with a similar silence between notes. Under WINDOWS or OS/2, you can hardly can recognize the output as the same. The notes are the same, because they are controlled by the timer. The length of each note and the silence between them are much longer. This gives you an idea of all the operations that must be performed by the operating system before the program can use the timer.
There is another aspect of multitasking that needs to be considered and is the resources. We call resources all the elements of the computer that a program can use. Resources are memory, the display, the keyboard, the disks, the printer, the modem, the timers, the CD-ROM, and all others. When you run a program under a non-multitasking system like DOS, all the resources are property of the program. Let us consider memory. In all computers there are programs in memory like the drivers for the printer and the disks, the resident part of DOS, and whatever else you have loaded. Normally, a program should not write on these areas of memory. There is nobody looking over the shoulder of the program to see that it does not. If the program writes on any of these areas, the system crashes. The same with all other resources.
In the case of a multitasking operating system all the resources belong to the operating system and none to the program. The operating system allots some memory to the program while it is running, but the operating system is continuously looking over the shoulder of the program to see that it obeys the rule. Have you seen those "Violation" messages from WINDOWS or OS/2? The same happens with all resources.
A program then, cannot use the resources of the computer. The operating system does it. Consider painting a picture on the screen dot by dot. A DOS program sends the dots to the screen. There are even procedures for storing the dots directly on the screen without using the DOS routines. A picture of the whole screen appears almost instantaneously. If your program paints a picture of the whole screen under a multitasking environment, the program needs to ask the operating system to paint each dot. Naturally, the operating system has to check if the dot belongs to another program and who has priority. If the program is not supposed to use that dot, the operating system denies the request. The result is that the picture is painted very slowly, like a curtain coming down across the screen.
How can you find how your operating system does multitasking? It is not easy. You can have an idea by running two programs simultaneously. Let us take an example from WINDOWS. Open two programs, each on its own window. Better if the windows are not overlapping. Choose two programs that do something visible. For example, I have the VIDEO FOR WINDOWS package. It has two programs WINCAPT and WINEDIT. They capture pictures and edit them respectively. WINCAPT shows continuously pictures from the video input. While the program is running you see the pictures from the source you have connected. They change all the time, almost like TV. If you click on the WINEDIT window, you see that while WINEDIT is waiting for your command, WINCAPT is showing pictures. If you give a command to WINEDIT, you see the pictures in WINCAPT stop while the command is executed by WINEDIT. When WINEDIT ends its command, WINCAPT shows pictures again. There are some commands that permit WINCAPT to catch the processor for a little while and update one picture.
A simpler example is with the mouse. Open File Manager. Tell File Manager to copy a file from one place to another. Choose a long file. While the copying is being done, click the mouse to change to another window. The mouse command will not be executed until File Manager finishes with the file, or finds a hole in the process. In this way you see that WINDOWS uses task switching to approximate multitasking. You will also see that WINDOWS defines the tasks quite rough.
If you have access to a UNIX station, or if you have LINUX, the same experiment will show you that the two programs run very smooth. Actually, in a UNIX station you are time sharing the use of the processor with all the other stations in the system. Only when the activity in the system is very high you will notice that your commands are not executed immediately.
The bad part of multitasking is that the word has been caught by the advertising industry, and used and misused very much. At this time, an operating system that tells you that permits multitasking does not tell you anything. It needs also to explain the procedure used for doing it. Since this can become quite complex, it is seldom done. I have not seen any operating system explaining how it does multitasking.
Note that DOS permits multitasking. I have a DOS program that formats diskettes in the background, effectively doing multitasking. You do not notice any slowing down of any other program you run, because the formatting program does one sector at a time. From what we said before, we know this program uses task switching and that the tasks are defined quite fine. There is an additional advantage when running multitasking under DOS: since there is no operating system, the program does not need to ask for permission each time it needs to use some resources. There is a disadvantage: if the program tries to write to the floppy disk, there might be a crash.
I do not know if I have clarified the topic but I have tried my best. It should be clear that current computers cannot do multitasking. The moral about multitasking is not to use the term, that does not have a clear definition. The best way is to use terms like task switching, time sharing, that have well understood meanings.
Comparing two operating system is not easy. If one does time sharing and the other task switching, you know time sharing gives superior results with fast processors. You cannot compare two operating systems that use task switching, unless you know how they define each task. The one that defines the tasks as shorter operations will give smoother results.
Finally, wherever you compare two operating systems you need to know what operations it performs during the switching of tasks. This is the overhead. A system with a large overhead is slower than one with less overhead.
I want to end quoting from a letter to the editor in OS/2 Magazine, August 1995: "If one truly does not need multitasking, one ought to stick with good old DOS."