Category: 

What Is Context Switching?

Article Details
  • Written By: T.S. Adams
  • Edited By: M. C. Hughes
  • Last Modified Date: 21 August 2016
  • Copyright Protected:
    2003-2016
    Conjecture Corporation
  • Print this Article
Free Widgets for your Site/Blog
In late 19th-century London, mail was delivered to residential addresses up to twelve times each day.   more...

September 28 ,  1924 :  Two US military planes complete the first flights around the world.  more...

One of the biggest steps forward in the design and operation of central processing units (CPUs) came when the designers of computer operating systems developed techniques to allow users to multitask. Multitasking in reference to computers is the practice of running two or more programs at the same time. From an end-user point of view, this might not seem complicated or farfetched, but it actually represents a considerable leap in system design. In multitasking, the CPU must juggle all of the operations for the different active programs, recording where it is with each program as the user toggles back and forth between them. Context switching is the process that allows the CPU to remember and restore states for a variety of active programs, enabling it to complete this juggling act.

During context switching, the CPU drops whatever program it is currently handling, storing the specific place it was in in that program so it can resume its progress later. To put that in perspective, context switching is a bit like reading multiple books at the same time, constantly switching back and forth between them while always remembering the page numbers for each. The "page number" information for programs during a context switching operation is held by the process control block (PCB). The PCB is also sometimes referred to as the "switchframe." This information is stored in memory within the actual CPU, until it is needed again.

Ad

Context switching occurs during three possible situations: interrupt handling, multitasking, and user switching. In interrupt handling, another program "interrupts" the current program while it is running. Once the CPU receives the interrupt, it performs a context switch to juggle between the running program and the program requesting immediate data. In multitasking, the CPU flops back and forth between the programs, giving a time slice of processing time to each and performing a context switching operation to change between the two. For some operating systems, a context switch is also performed during a user switch for the operating system, although this is not expressly required.

Either the operating system or the computer's hardware can control context switching. Some modern operating systems and are designed to control context switching through the operating system itself, ignoring any built-in hardware support for the procedure. This allows the operating system to save more information during a context switch, allowing it to preserve more information about the switch.

Ad

You might also Like

Recommended

Discuss this Article

Post your comments

exception 'Exception' with message 'error writing captcha: Duplicate entry '2147483647' for key 'PRIMARY'' in /ssd/www/wisegeek/public_html/_core/classes/public/Captcha.php:44
Stack trace:
#0 /ssd/www/wisegeek/public_html/_core/controls/public/ControlDiscussionPostBox.php(324): Captcha->createCaptcha()
#1 /ssd/www/wisegeek/public_html/framework/classes/Control.php(104): ControlDiscussionPostBox->preRender(false)
#2 /ssd/www/wisegeek/public_html/framework/classes/Control.php(149): Control->render()
#3 /ssd/www/wisegeek/public_html/tpl/default-nocustom-lu/pages/public/article/article.htm(526): Control->__toString()
#4 /ssd/www/wisegeek/public_html/framework/classes/Control.php(300): require('/ssd/www/wisege...')
#5 /ssd/www/wisegeek/public_html/framework/classes/Control.php(309): Control->requireTpl('pages/public/ar...', Object(PageArticleCom), true)
#6 /ssd/www/wisegeek/public_html/framework/classes/Control.php(131): Control->renderTpl('pages/public/ar...', Object(PageArticleCom))
#7 /ssd/www/wisegeek/public_html/framework/classes/FormDataControl.php(87): Control->renderTemplate()
#8 /ssd/www/wisegeek/public_html/framework/classes/Control.php(109): FormDataControl->renderTemplate()
#9 /ssd/www/wisegeek/public_html/framework/classes/ScriptPage.php(50): Control->render(false)
#10 /ssd/www/wisegeek/public_html/framework/classes/Control.php(149): ScriptPage->render()
#11 /ssd/www/wisegeek/public_html/framework/classes/Page.php(97): Control->__toString()
#12 /ssd/www/wisegeek/public_html/_core/classes/public/PublicFrontController.php(443): Page->processRequest()
#13 /ssd/www/wisegeek/public_html/_core/classes/public/PublicFrontController.php(7): PublicFrontController->renderPage()
#14 /ssd/www/wisegeek/public_html/index.php(11): PublicFrontController::run()
#15 {main}