Computer multitasking: Difference between revisions

Content deleted Content added
m Add `to`
AnomieBOT (talk | contribs)
m Dating maintenance tags: {{Unsourced section}}
 
(156 intermediate revisions by 90 users not shown)
Line 1:
{{Short description|Concurrent execution of multiple processes}}
{{redirect|Multitasking|human multitasking|Human multitasking|multitasking in media consumption|Media multitasking}}
[[File:Desktop-Linux-Mint.png|thumb|This computer is running linux ming(ubuntu) XCFE desktop environment VLC, GIMP, VIM, Calculator, Calendar and Firefox.|thumb|right|350px360px|Modern desktop operating systems are capable of handling large numbers of different processes at the same time. This screenshot shows [[Linux Mint]] running simultaneously [[Xfce]] desktop environment, [[Firefox]], a calculator program, the built-in calendar, [[Vim (text editor)|Vim]], [[GIMP]], and [[VLC media player]].]]
{{Refimprove|date=February 2012}}
[[File:Microsoft_Windows_1.01_multitasking.png|thumb|right360px|Multitasking capabilities of [[Microsoft Windows 1.0|Microsoft Windows 1.01]] released in 1985, here shown running the MS-DOS Executive and Calculator programs]]
[[File:Desktop-Linux-Mint.png|thumb|This computer is running linux ming(ubuntu) XCFE desktop environment VLC, GIMP, VIM, Calculator, Calendar and Firefox.|thumb|right|350px|Modern desktop operating systems are capable of handling large numbers of different processes at the same time. This screenshot shows [[Linux Mint]] running simultaneously [[Xfce]] desktop environment, [[Firefox]], a calculator program, the built-in calendar, [[Vim (text editor)|Vim]], [[GIMP]], and [[VLC media player]].]]
[[File:Microsoft_Windows_1.01_multitasking.png|thumb|right|Multitasking capabilities of [[Microsoft Windows 1.0|Microsoft Windows 1.01]] released in 1985, here shown running the MS-DOS Executive and Calculator programs]]
 
In [[computing]], '''multitasking''' is a concept of performing multiplethe [[Taskconcurrent computing|tasksconcurrent]] execution of multiple tasks (also known as [[Process (computing)|processes]]) over a certain period of time by executing them [[concurrent computing|concurrently]]. New tasks start andcan interrupt already started ones before they have reached completionfinish, instead of executingwaiting thefor tasks sequentially so each started task needsthem to reach its end before a new one is started. As a result, a computer executes segments of multiple tasks in an interleaved manner, while the tasks share common processing resources such as [[central processing unit]]s (CPUs) and [[main memory]]. Multitasking automatically interrupts the running program, saving its state (partial results, memory contents and computer register contents) and loading the saved state of another program and transferring control to it. This "[[context switch]]" may be initiated at fixed time intervals ([[pre-emptive multitasking]]), or the running program may be coded to signal to the supervisory software when it can be interrupted ([[cooperative multitasking]]).
 
Multitasking does ''not'' necessarily mean that multiple tasks are executing at exactly the same time (simultaneously). In other words, multitasking does not implyrequire [[Parallel computing|parallel execution]], butof itmultiple doestasks meanat that more than one task can be part-way through execution atexactly the same time; instead, andit thatallows more than one task isto advancingadvance over a given period of time.<ref>{{cite web |title=Concurrency vs Parallelism, Concurrent Programming vs Parallel Programming |url=https://blogs.oracle.com/yuanlin/entry/concurrency_vs_parallelism_concurrent_programming |publisher=Oracle |accessdateaccess-date=March 23, 2016 |archive-url=https://web.archive.org/web/20160407121734/https://blogs.oracle.com/yuanlin/entry/concurrency_vs_parallelism_concurrent_programming |archive-date=April 7, 2016 |url-status=dead }}</ref> Even on [[multiprocessor]] or [[multicore]] computers, which have multiple CPUs/cores, allowing more than one task to be executed at once (physically, one per CPU or core), multitasking allows many more tasks to be run than there are CPUs.
 
Multitasking is a common feature of computer operating systems since at least the 1960s. It allows more efficient use of the computer hardware; when a program is waiting for some external event such as a user input or an [[input/output]] transfer with a peripheral to complete, the central processor can still be used with another program. In a [[time-sharing]] system, multiple human operators use the same processor as if it was dedicated to their use, while behind the scenes the computer is serving many users by multitasking their individual programs. In [[multiprogramming]] systems, a task runs until it must wait for an external event or until the operating system's [[Scheduling (computing)|scheduler]] forcibly swaps the running task out of the CPU. [[Real-time computing|Real-time]] systems such as those designed to control industrial robots, require timely processing; a single processor might be shared between calculations of machine movement, communications, and user interface.<ref>Anthony Ralston, Edwin D. Reilly (ed),''Encyclopedia of Computer Science Third Edition'', Van Nostrand Reinhold, 1993, {{ISBN|0-442-27679-6}}, articles "Multitasking" and "Multiprogramming"</ref>
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 (computing)|scheduling]] 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]]; the illusion of parallelism is achieved when context switches occur frequently enough. Operating systems may adopt one of many different scheduling strategies, which generally fall into the following categories:{{citation needed|date=July 2013}}
* 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 disk or tape, receiving a message from a network, reading from a terminal or other human input device) 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]] 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 computing|real-time]] 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.
 
Often multitasking operating systems include measures to change the priority of individual tasks, so that important jobs receive more processor time than those considered less significant. Depending on the operating system, a task might be as large as an entire application program, or might be made up of smaller [[thread (computing)|threads]] that carry out portions of the overall program.
The term "multitasking" has become an international term, as the same word is used in many other languages such as German, Italian, Dutch, Danish and Norwegian.
 
A processor intended for use with multitasking operating systems may include special hardware to securely support multiple tasks, such as [[memory protection]], and [[protection ring]]s that ensure the supervisory software cannot be damaged or subverted by user-mode program errors.
 
The term "multitasking" has become an international term, as the same word is used in many other languages such as German, Italian, Dutch, Romanian, Czech, Danish and Norwegian.
 
== Multiprogramming ==
In the early days of computing, [[CPU time]] was expensive, and [[peripheral]]s were very slow. When the computer ran a program that needed access to a peripheral, the central processing unit (CPU) would have to stop executing program instructions while the peripheral processed the data. This was usually very inefficient. Multiprogramming is a computing technique that enables multiple programs to be concurrently loaded and executed into a computer's memory, allowing the CPU to switch between them swiftly. This optimizes CPU utilization by keeping it engaged with the execution of tasks, particularly useful when one program is waiting for I/O operations to complete.
 
The [[Bull Gamma 60]], initially designed in 1957 and first released in 1960, was the first computer designed with multiprogramming in mind. Its architecture featured a central memory and a Program Distributor feeding up to twenty-five autonomous processing units with code and data, and allowing concurrent operation of multiple clusters.
The first computer using a multiprogramming system was the British ''[[LEO (computer)#Applications and successors|Leo III]]'' owned by [[J. Lyons and Co.]] During [[batch processing]], several different programs 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.{{citation needed|date=July 2013}}
 
TheAnother firstsuch computer using a multiprogramming system was the British ''[[LEO (computer)#Applications and successors|LeoLEO III]]'', ownedfirst byreleased [[J. Lyons andin Co1961.]] During [[batch processing]], several different programs 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.<ref>{{citationcite book|url=http://settle.ddns.net/LeoMan/Vol4P1.htm|title=MASTER PROGRAME AND PROGRAMME TRIALS SYSTEM PART 1 MASTER PROGRAMME SPECIFICATION|at=section 6 "PRIORITY CONTROL neededROUTINES"|date=JulyFebruary 20131965}}</ref>
The use of multiprogramming was enhanced by the arrival of [[virtual memory]] and [[virtual machine]] technology, which enabled individual programs to make use of memory and operating system resources as if other concurrently running programs were, for all practical purposes, non-existent and invisible to them.{{citation needed|date=July 2013}}
 
Multiprogramming doesn'tgives give anyno 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 in a deck of punched cards to an operator, and came back a few hours later for printed results. Multiprogramming greatly reduced wait times when multiple batches were being processed.<ref>{{citationCite neededweb|url=https://pediaa.com/what-is-the-difference-between-batch-processing-and-multiprogramming/|title=What is the Difference Between Batch Processing and Multiprogramming|last=Lithmee|date=July2019-05-20|website=Pediaa.Com|language=en-US|access-date=2020-04-14}}</ref><ref>{{Cite 2013web|url=https://www.notesjam.com/2017/09/evolution-of-operating-system.html|title=Evolution of Operating System|date=2017-09-29|access-date=2020-04-14}}</ref>
 
== {{Anchor|COOP|Cooperative multitasking/time-sharing}}Cooperative multitasking ==
{{Main|Cooperative multitasking}}
 
Early multitasking systems used applications that voluntarily ceded time to one another. This approach, which was eventually supported by many computer [[operating system]]s, is known today as cooperative multitasking. Although it is now rarely used in larger systems except for specific applications such as [[CICS]] or the [[JES2]] subsystem, cooperative multitasking was once the only scheduling scheme employed by [[Microsoft Windows]] (prior to [[Windows 95]] and [[Windows NT]]) and [[Classicclassic Mac OS]] (prior to [[macOS|Mac OS X]]) in order to enable multiple applications to be run simultaneously. [[Windows 9x]] also used cooperative multitasking, but only for 16-bit legacy applications, much the same way as pre-[[Mac OS X Leopard|Leopard]] [[PowerPC]] versions of Mac OS X used it for [[Classic (Mac OS X)|Classic]] applications. The network operating system [[NetWare]] used cooperative multitasking up to NetWare 6.5. Cooperative multitasking is still used today on [[RISC OS]] systems.<ref>
The expression "time sharing" usually designated to computers shared by interactive users at terminals, such as IBM's [[Time Sharing Option|TSO]], and [[CP/CMS|VM/CMS]]. The term "time-sharing" is no longer commonly used, having been replaced by "multitasking", following the advent of personal computers and workstations rather than shared interactive systems.
 
Early multitasking systems used applications that voluntarily ceded time to one another. This approach, which was eventually supported by many computer [[operating system]]s, is known today as cooperative multitasking. Although it is now rarely used in larger systems except for specific applications such as [[CICS]] or the [[JES2]] subsystem, cooperative multitasking was once the scheduling scheme employed by [[Microsoft Windows]] (prior to [[Windows 95]] and [[Windows NT]]) and [[Classic Mac OS]] (prior to [[macOS|Mac OS X]]) in order to enable multiple applications to be run simultaneously. [[Windows 9x]] also used cooperative multitasking, but only for 16-bit legacy applications, much the same way as pre-[[Mac OS X Leopard|Leopard]] [[PowerPC]] versions of Mac OS X used it for [[Classic (Mac OS X)|Classic]] applications. The network operating system [[NetWare]] used cooperative multitasking up to NetWare 6.5. Cooperative multitasking is still used today on [[RISC OS]] systems.<ref>
{{cite web
|url = http://www.riscos.info/index.php/Preemptive_multitasking
|title = Preemptive multitasking
|date = 2009-11-03 |accessdateaccess-date = 2014-07-27
|website = riscos.info
}}</ref>
Line 40 ⟶ 38:
 
== Preemptive multitasking ==
{{Main|Preemption (computing)#Preemptive multitasking}}
[[File:Kubuntu_21.04_(KDE_Plasma_5)_-_Virtual_Desktops.png|thumb|Kubuntu (KDE Plasma 5) four [[Virtual desktop]]s running multiple programs at the same time]]
 
Preemptive multitasking allows the computer system to more reliably guarantee to each process a regular "slice" of operating time. It also allows the system to deal rapidly 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. Preemptive multitasking was implemented in [[TOPS-10|the PDP-6 Monitor]] and [[MULTICSMultics]] in 1964, in [[OS/360 and successors#MFT|OS/360 MFT]] in 1967, and in [[Unix]] (in 1969, and was available in [[PDP-8#Programming facilities|some operating systems]] for computers as small as DEC's PDP-8; it is a core feature of all [[Unix-like]] operating systems, such as [[Linux]], [[Solaris (operating system)|Solaris]] and [[Berkeley Software Distribution|BSD]] with its [[Comparison of BSD operating systems|derivatives]],<ref>{{Citecite web
| url = http://www.ibiblio.org/team/intro/unix/what.html
| title = UNIX, Part One | work = The Digital Research Initiative
| date = 2002-01-30 | accessdateaccess-date = 2014-01-09
| publisher = ibiblio.org
}}</ref> as well as modern versions of Windows.
 
Possibly the earliest preemptive multitasking OS available to home users was [[Microware]]'s [[OS-9]], available for computers based on the [[Motorola 6809]] such as the [[TRS-80 Color Computer 2]],<ref name="rainbow198309_dynamicuno">{{ cite magazine | url=https://archive.org/details/198309Rainbow/page/236/mode/2up | title=Dynamic Uno | magazine=The Rainbow | last1=Downard | first1=Dan | date=September 1983 | access-date=9 May 2024 | pages=236–240 }}</ref> with the operating system supplied by Tandy as an upgrade for disk-equipped systems.<ref name="tandyrsc11">{{ cite book | url=https://archive.org/details/RSC-11_Computer_Catalog_1984_Radio_Shack_a/page/n52/mode/1up | title=1984 TRS-80 Catalog | publisher=Tandy Corporation | date=1984 | access-date=14 May 2024 | pages=53–54 }}</ref> [[Sinclair QDOS]] on the [[Sinclair QL]] followed in 1984, but it was not a big success. Commodore's [[Amiga]] was released the following year, offering a combination of multitasking and multimedia capabilities. Microsoft made preemptive multitasking a core feature of their flagship operating system in the early 1990s when developing [[Windows NT 3.1]] and then [[Windows 95]]. In 1988 Apple offered [[A/UX]] as a [[UNIX System V]]-based alternative to the [[Classic Mac OS]]. In 2001 Apple switched to the [[NeXTSTEP]]-influenced [[Mac OS X]].
At any specific time, processes can be grouped into two categories: those that are waiting for input or output (called "[[I/O bound]]"), and those that are fully utilizing the CPU ("[[CPU bound]]"). In primitive systems, the software would often "[[Polling (computer science)|poll]]", or "[[Busy waiting|busywait]]" 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.{{citation needed|date=July 2013}}
 
A similar model is used in [[Windows 9x]] and the [[Windows NT|Windows NT family]], where native 32-bit applications are multitasked preemptively, and legacy 16-bit [[Windows 3.1x|Windows 3.x]] programs are multitasked cooperatively within a single process, although in the NT family it is possible to force a 16-bit application to run as a separate preemptively multitasked process.<ref>{{cite magazine|url=http://www.smartcomputing.com:80/editorial/article.asp?article=articles%2F2005%2Fs1606%2F08s06%2F08s06.asp|magazine=[[Smart Computing]]|title=Windows 2000 &16-Bit Applications|volume=16|issue=6|pages=32–33|date=June 2006|author=Joseph Moran|archive-url=https://web.archive.org/web/20090125104811/http://www.smartcomputing.com/editorial/article.asp?article=articles%2F2005%2Fs1606%2F08s06%2F08s06.asp|archive-date=January 25, 2009|deadurl=yes|dfurl-status=dead}}</ref> 64-bit editions of Windows, both for the [[x86-64]] and [[Itanium]] architectures, no longer provide support for legacy 16-bit applications, and thus provide preemptive multitasking for all supported applications.
The earliest preemptive multitasking OS available to home users was [[Sinclair QDOS]] on the [[Sinclair QL]], released in 1984, but very few people bought the machine. Commodore's powerful [[Amiga]], released the following year, was the first commercially successful home computer to use the technology, and its multimedia abilities make it a clear ancestor of contemporary multitasking personal computers. [[Microsoft]] made preemptive multitasking a core feature of their flagship operating system in the early 1990s when developing [[Windows NT 3.1]] and then [[Windows 95]]. It was later adopted on the Apple Macintosh by [[Mac OS X]] that, as a [[Unix-like]] operating system, uses preemptive multitasking for all native applications.
 
A similar model is used in [[Windows 9x]] and the [[Windows NT|Windows NT family]], where native 32-bit applications are multitasked preemptively, and legacy 16-bit [[Windows 3.1x|Windows 3.x]] programs are multitasked cooperatively within a single process, although in the NT family it is possible to force a 16-bit application to run as a separate preemptively multitasked process.<ref>{{cite magazine|url=http://www.smartcomputing.com:80/editorial/article.asp?article=articles%2F2005%2Fs1606%2F08s06%2F08s06.asp|magazine=[[Smart Computing]]|title=Windows 2000 &16-Bit Applications|volume=16|issue=6|pages=32–33|date=June 2006|author=Joseph Moran|archive-url=https://web.archive.org/web/20090125104811/http://www.smartcomputing.com/editorial/article.asp?article=articles%2F2005%2Fs1606%2F08s06%2F08s06.asp|archive-date=January 25, 2009|deadurl=yes|df=}}</ref> 64-bit editions of Windows, both for the [[x86-64]] and [[Itanium]] 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]] 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 is coupled with process prioritization to ensure that key activities were given a greater share of available [[process time]].<ref>{{citationCite journal |last1=Liu |first1=C. L. |last2=Layland |first2=James W. needed|date=July1973-01-01 |title=Scheduling Algorithms for Multiprogramming in a Hard-Real-Time Environment |journal=Journal of the ACM |volume=20 |issue=1 |pages=46–61 |doi=10.1145/321738.321743 |s2cid=59896693 |issn=0004-5411|doi-access=free 2013}}</ref>
 
== Multithreading ==
As multitasking greatly improved the throughput of computers, programmers started to implement applications as sets of cooperating processes (e.&nbsp;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.{{citation needed|date=July 2013}}
 
[[Thread (computer sciencecomputing)|Threads]] 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 effectively processes that run in the same memory context and share other resources with their [[parent process]]es, such as open files. Threads are described as ''lightweight processes'' because switching between threads does not involve changing the memory context.<ref>{{cite web
| url = http://www.redbooks.ibm.com/redpapers/pdfs/redp4285.pdf
| title = Linux Performance and Tuning Guidelines
| date = April 25, 2008
| accessdateaccess-date = March 1, 2015
| author1 = Eduardo Ciliendo
| author2 = Takechika Kunimasa
| website = redbooks.ibm.com
| publisher = [[IBM]]
| format = PDF | page = 4
| archive-url = https://web.archive.org/web/20150226022205/http://www.redbooks.ibm.com/redpapers/pdfs/redp4285.pdf
}}</ref><ref>{{cite web
| archive-date = February 26, 2015
| url-status = dead
}}</ref><ref>{{cite web
| url = http://www.linfo.org/context_switch.html
| title = Context Switch Definition
| date = May 28, 2006
| accessdateaccess-date = February 26, 2015
| website = linfo.org
| archive-url = https://web.archive.org/web/20100218115342/http://www.linfo.org/context_switch.html
}}</ref><ref>{{cite web
| archive-date = February 18, 2010
| url-status = dead
}}</ref><ref>{{cite web
| url = http://www.tldp.org/FAQ/Threads-FAQ/Types.html
| title = What are threads (user/kernel)?
| date = September 8, 1997 | accessdateaccess-date = February 26, 2015
| website = tldp.org
}}</ref>
 
While threads are scheduled preemptively, some operating systems provide a variant to threads, named ''[[Fiber (computer science)|fiber]]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 [[multiprocessing|machines with multiple processors]].{{Citation<ref>[http://csmoraitis.weebly.com/uploads/1/4/1/9/14190245/multitasking_-_different_methods.pdf needed|date=AugustMultitasking 2007}}different methods]
 
Accessed on February 19, 2019</ref>
Some systems directly support [[Multithreading (computer hardware)|multithreading in hardware]].
 
Some systems directly support [[Multithreading (computer hardwarearchitecture)|multithreading in hardware]].
 
== Memory protection ==
{{Main|Memory protection}}
{{unsourced section|date=March 2025}}
 
Essential to any multitasking system is to safely and effectively share access to system resources. Access to memory must be strictly managed to ensure that no process can inadvertently or deliberately read or write to memory locations outside the process's address space. This is done for the purpose of general system stability and data integrity, as well as data security.
 
Line 96 ⟶ 103:
 
== Memory swapping ==
Use of a [[Virtual memory|swap file]] 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.<ref>{{citationcite neededweb|dateurl=Julyhttps://kb.iu.edu/d/aagb|title=What 2013is a swap file?|website=kb.iu.edu|language=en|access-date=2018-03-26}}</ref>
 
== Programming ==
Over the years, multitasking systems have been refined. Modern operating systems generally include detailed mechanisms for prioritizing processes, while [[symmetric multiprocessing]] has introduced new complexities and capabilities.<ref>{{citationcite neededweb|dateurl=Julyhttp://cis2.oc.ctc.edu/oc_apps/Westlund/xbook/xbook.php?unit=04&proc=page&numb=5|title=Operating 2013Systems Architecture|website=cis2.oc.ctc.edu|access-date=2018-03-17}}</ref>
Processes that are entirely independent are not much trouble to program in a multitasking environment. 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.{{citation needed|date=July 2013}}
 
Various [[concurrent computing]] techniques are used to avoid potential problems caused by multiple tasks attempting to access the same resource.{{citation needed|date=July 2013}}
 
Bigger systems were sometimes built with a central processor(s) and some number of [[Channel I/O|I/O processors]], a kind of asymmetric [[multiprocessing]].{{citation needed|date=July 2013}}
 
Over the years, multitasking systems have been refined. Modern operating systems generally include detailed mechanisms for prioritizing processes, while [[symmetric multiprocessing]] has introduced new complexities and capabilities.{{citation needed|date=July 2013}}
 
== See also ==
Line 114 ⟶ 115:
{{Reflist}}
 
{{Operating Systemsystems}}
{{Parallel computing}}
{{Authority control}}
 
{{DEFAULTSORT:Computer Multitasking}}