Pages

Friday, April 16, 2010

How multi tasking works?

In this decade, it would be very silly to ask someone whether his/her operating system multi tasking? It would be silly too is asked in the mid 1990’s. The concept of windows was originally developed by Xerox PARC. Surprising isn’t it because the very developer of the concept isn’t in this field today. Everybody has in their minds Bill Gates or someone else when asked about the inventor of multi tasking operating systems. Now, when the computers were first introduced, single tasking systems were just in the developmental stage. Single tasking refers to the ability to carry out not more than one task at a time. This was rather annoying for users because, since the computers were not too fast and the abilities were limited, users had to waste much of their time carrying out single tasks. For an instance if a user had to copy a really large file (500 KB was considered a really huge file in those times) to some destination, type a letter to the department and do some analysis, then he’ll first copy the file to that location, wait for really long period and then resume other activities. Now, this really wasted a lot of time because other tasks which ordered sequentially were left pending because the first task in the order was taking too much time to complete. Therefore, a need to carry out various tasks simultaneously arose. Lets skip the historical facts and head straight to what multi-tasking really is.

Literally, multi tasking refers to the ability to co-execute one or more than one task simultaneously. If you were the researcher at that time, then you would have thought that using more than one CPU can promote multi tasking. Yes, it can very well do it efficiently but the problem was that if each CPU is assigned a single task, then a system with 2 CPU will be referred as ‘dual tasking’, a system with three CPU will be referred as ‘triple tasking’ and so on. That would consume a lot of electricity and generate heat. Also, that would be foolishness because according to a survey, an average user has 4-6 windows open and 70-80 processes running simultaneously. According to the above mentioned ‘one CPU one Task’ process, that would require 70-80 CPUs to operate a normal computer! Isn’t that madness? That’s why computer scientists developed the threading method.

In this method, every small task is assigned a thread. A thread is a very simple process. A thread can have simple task assigned to it like bit-by-bit file copier etc. Now these threads are further managed by a small program called scheduler. This scheduler manages all threads. It keeps track of new threads, progress of current threads and completed threads. Once a thread (process associated with it) is completed, it is disposed off the memory of computer. Scheduler sorts the threads according to their priority like those threads associated with display are at highest priority than others. Display threads are threads associated with display of windows, graphics etc. If these do not get higher priority, then you won’t get up-to-date display. For an instance, when you double click a folder, all display threads are triggered. They all one by one, in a matter of nanoseconds or picoseconds paint the window, menus and text by painting the pixels of screen. Similarly all threads are executed. Say, 3 threads are scheduled by the scheduler having names A, B and C respectively. Assume that A is copying file, B is downloading file and C is clock. You start the computer. Operating system reads hard drive and executed scheduler. Scheduler reads threads to be executed and arranges them according to their priority. Say, the priority is A-B-C(Disregarding the display threads). Scheduler executes thread A. 1 bit of file is copied (Actual value is different) and progress variable is updated. Task takes few nanoseconds to complete. Scheduler pauses A and executed B. 1 bit of file is downloaded and progress variable is updated. B is paused and C is executed. Clock time is checked. If it is changed, time and date variable is updated. All updated variables are applied and display is updated. Again scheduler executed thread A and the process continues. But this process is so fast that it goes unnoticed. You feel as if all three processes are running simultaneously. Rather it is single tasking only but it is modified way of single tasking. In reality, there are thousands of threads. All these are executed several times in a second. Since each task is going bit by bit, it goes very fast.

Today, most of all operating systems are multi tasking. Linux is an operating system that is really fully multi tasking. This is because the command line in linux is multi tasking and not only the GUI. In command line, you can simultaneously run more than one command. This functionality is not available in windows.
There’s much more difference between the multi tasking techniques implemented by different operating systems. We shall see about this some other time. 

Ads

Look into BLOG ARCHIVE for more posts.