All Topics  
Computer multitasking

 

   Email Print
   Bookmark   Link






 

Computer multitasking



 
 
In computing, multitasking is a method by which multiple tasks, also known as processes, share common processing resources such as a CPU
Central processing unit

A central processing unit is an electronic circuit that can execute computer programs. This broad definition can easily be applied to many early computers that existed long before the term "CPU" ever came into widespread usage....
. In the case of a computer with a single CPU, only one task is said to be running at any point in time, meaning that the CPU is actively executing instructions for that task. Multitasking solves the problem by scheduling
Scheduling (computing)

Scheduling is a key concept in computer multitasking and multiprocessing operating system design, and in real-time operating system design. In modern operating systems, there are typically many more processes running than there are CPUs available to run them....
 which task may be the one running at any given time, and when another waiting task gets a turn.






Discussion
Ask a question about 'Computer multitasking'
Start a new discussion about 'Computer multitasking'
Answer questions from other users
Full Discussion Forum



Encyclopedia


In computing, multitasking is a method by which multiple tasks, also known as processes, share common processing resources such as a CPU
Central processing unit

A central processing unit is an electronic circuit that can execute computer programs. This broad definition can easily be applied to many early computers that existed long before the term "CPU" ever came into widespread usage....
. In the case of a computer with a single CPU, only one task is said to be running at any point in time, meaning that the CPU is actively executing instructions for that task. Multitasking solves the problem by scheduling
Scheduling (computing)

Scheduling is a key concept in computer multitasking and multiprocessing operating system design, and in real-time operating system design. In modern operating systems, there are typically many more processes running than there are CPUs available to run them....
 which task may be the one running at any given time, and when another waiting task gets a turn. The act of reassigning a CPU from one task to another one is called a context switch
Context switch

A context switch is the computing process of storing and restoring the State of a Central processing unit such that multiple Process es can share a single CPU resource....
. When context switches occur frequently enough the illusion of parallelism
Parallel computing

Parallel computing is a form of computing in which many calculations are carried out simultaneously, operating on the principle that large problems can often be divided into smaller ones, which are then solved Concurrency ....
 is achieved. Even on computers with more than one CPU (called multiprocessor machines), multitasking allows many more tasks to be run than there are CPUs.

Operating systems may adopt one of many different scheduling strategies
Scheduling (computing)

Scheduling is a key concept in computer multitasking and multiprocessing operating system design, and in real-time operating system design. In modern operating systems, there are typically many more processes running than there are CPUs available to run them....
, which generally fall into the following categories:
  • In multiprogramming systems, the running task keeps running until it performs an operation that requires waiting for an external event (e.g. reading from a tape) or until the computer's scheduler forcibly swaps the running task out of the CPU. Multiprogramming systems are designed to maximize CPU usage.
  • In time-sharing
    Time-sharing

    Time-sharing refers to sharing a computing resource among many users by Computer multitasking. Its introduction in the 1960s, and emergence as the prominent model of computing in the 1970s, represents a major historical shift in the history of computing....
     systems, the running task is required to relinquish the CPU, either voluntarily or by an external event such as a hardware interrupt. Time sharing systems are designed to allow several programs to execute apparently simultaneously.
  • In real-time
    Real-time computing

    In computer science, real-time computing is the study of Computer hardware and computer software systems that are subject to a "real-time constraint"?i.e., operational deadlines from event to system response....
     systems, some waiting tasks are guaranteed to be given the CPU when an external event occurs. Real time systems are designed to control mechanical devices such as industrial robots, which require timely processing.


The term time-sharing is no longer commonly used, having been replaced by simply multitasking.

Multiprogramming

In the early days of computing, CPU time
CPU time

CPU time or CPU usage is the amount of time a computer program uses in processing central processing unit instructions, as opposed for example to waiting for input/output operations....
 was expensive, and peripheral
Peripheral

A peripheral is a device attached to a host computer behind the chipset whose primary functionality is dependent upon the host, and can therefore be considered as expanding the hosts capabilities, while not forming part of the system's core computer architecture....
s were very slow. When the computer ran a program that needed access to a peripheral, the CPU would have to stop executing program instructions while the peripheral processed the data. This was deemed very inefficient.

The first efforts to create multiprogramming systems took place in the 1960s. Several different programs in batch were loaded in the computer memory, and the first one began to run. When the first program reached an instruction waiting for a peripheral, the context of this program was stored away, and the second program in memory was given a chance to run. The process continued until all programs finished running.

Multiprogramming doesn't give any guarantee that a program will run in a timely manner. Indeed, the very first program may very well run for hours without needing access to a peripheral. As there were no users waiting at an interactive terminal, this was no problem: users handed a deck of punched cards to an operator, and came back a few hours later for printed results. Multiprogramming greatly reduced the waiting.

The early OS/360 primary control program (PCP) followed the above model but was replaced the very next year, 1967, by MFT
MFT (operating system)

In the history of IBM mainframe operating systems, multiprogramming with a fixed number of tasks was one of the three available configurations of the OS/360's control program....
 which limited the amount of CPU time any single process could consume before being switched out.

Cooperative multitasking/time-sharing

When computer usage evolved from batch mode to interactive mode, multiprogramming was no longer a suitable approach. Each user wanted to see his program running as if it was the only program in the computer. The use of time sharing made this possible, with the qualification that the computer would not seem as fast to any one user as it really would be if it were running only that user's program.

Early multitasking systems consisted of suites of related applications that voluntarily ceded time to each other. This approach, which was eventually supported by many computer operating system
Operating system

An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer....
s, is today known as cooperative multitasking. Although it is rarely used in larger systems, Microsoft Windows
Microsoft Windows

Microsoft Windows is a series of software operating systems and graphical user interfaces produced by Microsoft. Microsoft first introduced an operating environment named Windows in November 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces ....
 prior to Windows 95
Windows 95

Windows 95 is a consumer-oriented graphical user interface-based operating system. It was released on August 24, 1995 by Microsoft, and was a significant progression from the company's previous Microsoft Windows products....
 and Windows NT
Windows NT

Windows NT is a family of operating systems produced by Microsoft, the first version of which was released in July 1993. It was originally designed to be a powerful high-level-language-based, processor-independent, multiprocessing, multiuser operating system with features comparable to Unix....
, and Mac OS
Mac OS

Mac OS is the trademarked name for a series of graphical user interface-based operating systems developed by Apple Inc. for their Macintosh line of computer systems....
 prior to Mac OS X
Mac OS X

Mac OS X is a line of computer operating systems developed, marketed, and sold by Apple Inc., and since 2002 has been included with all new Macintosh computer systems....
 both used cooperative multitasking to enable the running of multiple applications simultaneously. Windows 9x
Windows 9x

Windows 9x is the family of Microsoft Windows operating systems that comprises the hybrid 16/32-bit Windows versions: Windows 95, Windows 98, which were produced in the 1990s, and often also Windows Me, which was produced in 2000....
 also used cooperative multitasking, but only for 16-bit legacy applications, much the same way as pre-Leopard
Mac OS X v10.5

Mac OS X version 10.5 "Leopard" is the sixth Software version of Mac OS X, Apple Inc. desktop and server operating system for Apple Macintosh computers, and the successor to Mac OS X v10.4 "Tiger"....
 PowerPC
PowerPC

PowerPC is a RISC instruction set architecture created by the 1991 Apple Inc.?IBM?Motorola alliance, known as AIM alliance. Originally intended for personal computers, PowerPC CPUs have since become popular embedded system and high-performance processors....
 versions of Mac OS X used it for Classic
Classic (Mac OS X)

Classic, or Classic Environment, was a Computer hardware and software abstraction layer in Mac OS X that allowed Application software compatible with Mac OS 9 to run on the Mac OS X operating system....
 applications. Cooperative multitasking is still used today on RISC OS
RISC OS

RISC OS is a computer operating system which was originally developed by Acorn Computers Ltd in Cambridge, England for their ARM architecture based computers....
 systems.

Because a cooperatively multitasked system relies on each process to regularly give time to other processes on the system, one poorly designed program can cause the whole system to hang
Hang (computing)

In computing, a hang or freeze occurs when either a single computer program or the whole system becomes unresponsive to computer keyboard and computer mouse input/output....
.

Preemptive multitasking/time-sharing


Preemptive multitasking allows the computer system to more reliably guarantee each process a regular "slice" of operating time. It also allows the system to rapidly deal with important external events like incoming data, which might require the immediate attention of one or another process.

Operating systems were developed to take advantage of these hardware capabilities and run multiple processes preemptively. For example, preemptive multitasking was implemented in the earliest version of Unix
Unix

Unix is a computer operating system originally developed in 1969 by a group of American Telephone & Telegraph employees at Bell Labs, including Ken Thompson , Dennis Ritchie, Douglas McIlroy, and Joe Ossanna....
  in 1969, and is standard in Unix and Unix-like
Unix-like

A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....
 operating systems, including Linux
Linux

Linux is a generic term referring to Unix-like computer operating systems based on the Linux kernel. Their development is one of the most prominent examples of free and open source software collaboration; typically all the underlying source code can be used, freely modified, and redistributed by anyone under the terms of the GNU GPL license...
, Solaris and BSD with its derivatives
Comparison of BSD operating systems

There are a number of Unix-like operating systems based on or descended from the Berkeley Software Distribution series of Unix variants....
.

At any specific time, processes can be grouped into two categories: those that are waiting for input or output (called "I/O bound
IO bound

In computer science, I/O bound refers to a condition in which the time it takes to complete a computation is determined principally by the period of time spent waiting for input/output operations to be completed....
"), and those that are fully utilizing the CPU ("CPU bound
CPU bound

In computer science, CPU bound is when the time for a computer to complete a task is determined principally by the speed of the Central processing unit: processor utilization is high, perhaps at 100% usage for many seconds or minutes....
"). In primitive systems, the software would often "poll", or "busywait
Busy waiting

In software engineering, busy waiting or spinning is a technique in which a process repeatedly checks to see if a condition is true, such as waiting for Computer keyboard input or waiting for a lock to become available....
" while waiting for requested input (such as disk, keyboard or network input). During this time, the system was not performing useful work. With the advent of interrupts and preemptive multitasking, I/O bound processes could be "blocked", or put on hold, pending the arrival of the necessary data, allowing other processes to utilize the CPU. As the arrival of the requested data would generate an interrupt, blocked processes could be guaranteed a timely return to execution.

The earliest preemptive multitasking OS available to home users was Sinclair QDOS
Sinclair QDOS

QDOS was the computer multitasking operating system found on the Sinclair QL personal computer and its clones. It was designed by Tony Tebby whilst working at Sinclair Research, as an in-house alternative to another, later cancelled, operating system commissioned from GST Computer Systems....
 on the Sinclair QL
Sinclair QL

The Sinclair QL , was a personal computer launched by Sinclair Research Ltd in 1984, as the successor to the Sinclair ZX Spectrum. The QL was aimed at the hobbyist and small business markets, but failed to achieve commercial success....
 released in 1984. Preemptive multitasking was later adopted on the Apple Macintosh by Mac OS
Mac OS

Mac OS is the trademarked name for a series of graphical user interface-based operating systems developed by Apple Inc. for their Macintosh line of computer systems....
 9.x as an additional API, i.e. the application could be programmed to use the preemptive or co-operative model, and all legacy applications were multitasked cooperatively within a single process. Mac OS X
Mac OS X

Mac OS X is a line of computer operating systems developed, marketed, and sold by Apple Inc., and since 2002 has been included with all new Macintosh computer systems....
, being a Unix-like
Unix-like

A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....
 system, uses preemptive multitasking for all native applications, although Classic
Classic (Mac OS X)

Classic, or Classic Environment, was a Computer hardware and software abstraction layer in Mac OS X that allowed Application software compatible with Mac OS 9 to run on the Mac OS X operating system....
 applications may be multitasked cooperatively as they run in fact under Mac OS 9 running as OS X process.

A similar model is used in Windows 9x
Windows 9x

Windows 9x is the family of Microsoft Windows operating systems that comprises the hybrid 16/32-bit Windows versions: Windows 95, Windows 98, which were produced in the 1990s, and often also Windows Me, which was produced in 2000....
 and Windows NT family
Windows NT

Windows NT is a family of operating systems produced by Microsoft, the first version of which was released in July 1993. It was originally designed to be a powerful high-level-language-based, processor-independent, multiprocessing, multiuser operating system with features comparable to Unix....
, where native 32-bit applications are multitasked preemptively, and legacy 16-bit Windows 3.x
Windows 3.1x

Windows 3.1x is a line of operating systems produced by Microsoft for use on personal computers. The line began with Windows 3.1, which was released in March 1992 as a successor to Windows 3.0....
 are multitasked cooperatively within a single process, although in the NT family it is possible to force 16-bit application to run as a separate preemptively multitasked process. 64-bit editions of Windows, both for the x86-64
X86-64

x86-64 is a superset of the x86. x86-64 Central processing units can run existing 32-bit or 16-bit x86 programs at full speed, but also support new programs written with a 64-bit address space and other additional capabilities....
 and Itanium
Itanium

Itanium is the brand name for 64-bit Intel microprocessors that implement the Intel Itanium architecture . Intel has released two processor families using the brand: the original Itanium and the Itanium 2....
 architectures no longer provide support for legacy 16-bit applications, and thus provide preemptive multitasking for all supported applications.

Real time

Another reason for multitasking was in the design of real-time computing
Real-time computing

In computer science, real-time computing is the study of Computer hardware and computer software systems that are subject to a "real-time constraint"?i.e., operational deadlines from event to system response....
 systems, where there are a number of possibly unrelated external activities needed to be controlled by a single processor system. In such systems a hierarchical interrupt system was coupled with process prioritization to ensure that key activities were given a greater share of available process time.

Multithreading

As multitasking greatly improved the throughput of computers, programmers started to implement applications as sets of cooperating processes (e.g. one process gathering input data, one process processing input data, one process writing out results on disk.) This, however, required some tools to allow processes to efficiently exchange data.

Threads
Thread (computer science)

In computer science, a thread of execution is a Fork of a computer program into two or more Concurrency running task s. The implementation of threads and process es differs from one operating system to another, but in most cases, a thread is contained inside a process....
 were born from the idea that the most efficient way for cooperating processes to exchange data would be to share their entire memory space. Thus, threads are basically processes that run in the same memory context. Threads are described as lightweight because switching between threads does not involve changing the memory context.

While threads are scheduled preemptively, some operating systems provide a variant to threads, named fiber
Fiber (computer science)

In computer science, a fiber is a particularly lightweight thread of execution.Like threads, fibers share address space; where a distinction exists, it is that fibers use Computer multitasking#Cooperative multitasking/time-sharing while threads use pre-emptive multitasking....
s
, that are scheduled cooperatively. On operating systems that do not provide fibers, an application may implement its own fibers using repeated calls to worker functions. Fibers are even more lightweight than threads, and somewhat easier to program with, although they tend to lose some or all of the benefits of threads on machines with multiple processors
Multiprocessing

Multiprocessing is the use of two or more CPU within a single computer system. The term also refers to the ability of a system to support more than one processor and/or the ability to allocate tasks between them....
.

Some systems directly support multithreading in hardware
Multithreading (computer hardware)

Multithreading computers have hardware support to efficiently execute multiple thread . These are distinguished from multiprocessing systems in that the threads have to share the resources of single core: the computing units, the CPU caches and the translation lookaside buffer ....
.

Memory protection


When multiple programs are present in memory, an ill-behaved program may (inadvertently or deliberately) overwrite memory belonging to another program, or even to the operating system itself.

The operating system therefore restricts the memory accessible to the running program. A program trying to access memory outside its allowed range is immediately stopped before it can change memory belonging to another process.

Another key innovation was the idea of privilege levels. Low privilege tasks are not allowed some kinds of memory access and are not allowed to perform certain instructions. When a task tries to perform a privileged operation a trap
Trap (computing)

In computing and operating systems, a trap is a type of synchronization interrupt typically caused by an exception handling condition in a user process ....
 occurs and a supervisory program running at a higher level is allowed to decide how to respond. This created the possibility of virtualizing the entire system, including virtual peripheral devices. Such a simulation is called a virtual machine
Virtual machine

In computer science, a virtual machine is a software implementation of a machine that executes programs like a real machine.Definitions...
 operating system. Early virtual machine systems did not have virtual memory
Virtual memory

Virtual memory is a computer system technique which gives an application program the impression that it has contiguous working memory , while in fact it may be physically fragmented and may even overflow on to disk storage....
, but both are common today.

Memory swapping

Use of a swap file
Virtual memory

Virtual memory is a computer system technique which gives an application program the impression that it has contiguous working memory , while in fact it may be physically fragmented and may even overflow on to disk storage....
 or swap partition is a way for the operating system to provide more memory than is physically available by keeping portions of the primary memory in secondary storage. While multitasking and memory swapping are two completely unrelated techniques, they are very often used together, as swapping memory allows more tasks to be loaded at the same time. Typically, a multitasking system allows another process to run when the running process hits a point where it has to wait for some portion of memory to be reloaded from secondary storage.

Programming in a multitasking environment

Processes that are entirely independent are not much trouble to program. Most of the complexity in multitasking systems comes from the need to share computer resources between tasks and to synchronize the operation of co-operating tasks. Various concurrent computing
Concurrent computing

Concurrent computing is a form of computing in which computer program are designed as collections of interacting computational processes that may be executed in Parallel computing....
 techniques are used to avoid potential problems caused by multiple tasks attempting to access the same resource.

Bigger computer systems were sometimes built with a central processor(s) and some number of I/O processors, a kind of asymmetric multi-processing.

Over the years, multitasking systems have been refined. Modern operating systems generally include detailed mechanisms for prioritizing processes, while symmetric multiprocessing
Symmetric multiprocessing

In computing, symmetric multiprocessing or SMP involves a multiprocessor computer-architecture where two or more identical processors can connect to a single shared main memory....
 has introduced new complexities and capabilities.

See also

  • Process
    Process (computing)

    In computing, a process is an Object of a computer program that is being sequentially executed by a computer system that has the ability to run several computer programs Concurrency ....
  • Process states
    Process states

    In a computer multitasking computer system, process may occupy a variety of state . These distinct states may not actually be recognized as such by the operating system kernel , however they are a useful abstraction for the understanding of processes....
  • Process time
  • Task
    Task (computers)

    A task is "an execution path through address space". In other words, a set of Computer program instruction s that are loaded in computer storage....