Index   Commented   Search   About

Context Switches

The scheduler maintains a queue of executable threads for each priority level. These are known as ready threads. When a processor becomes available, the system performs a context switch. The steps in a context switch are:

  1. Save the context of the thread that just finished executing.

  2. Place the thread that just finished executing at the end of the queue for its priority.

  3. Find the highest priority queue that contains ready threads.

  4. Remove the thread at the head of the queue, load its context, and execute it.

The following classes of threads are not ready threads.

  • Threads created with the CREATE_SUSPENDED flag

  • Threads halted during execution with the SuspendThread or SwitchToThread function

  • Threads waiting for a synchronization object or input.

Until threads that are suspended or blocked become ready to run, the scheduler does not allocate any processor time to them, regardless of their priority.

The most common reasons for a context switch are:

  • The time slice has elapsed.

  • A thread with a higher priority has become ready to run.

  • A running thread needs to wait.

When a running thread needs to wait, it relinquishes the remainder of its time slice.

Related Links

Software for Delphi and C++ Builder developers
Software for Visual Studio .NET developers
Software for Visual Basic 6 developers
Delphi Tips&Tricks
MegaDetailed.NET
TMS Scripter Studio Pro components for Delphi/C++Builder

More Online Helps

Win32 Multimedia Programmer's Reference (mmedia.hlp)
OLE Programmer's Reference (ole.hlp)
Microsoft Windows Pen API Programmer's Reference (penapi.hlp)
Microsoft Windows Sockets 2 Reference (sock2.hlp)
Microsoft Windows Telephony API (TAPI) Programmer's Reference (tapi.hlp)
Unix Manual Pages

Free Tech Secrets ;) Copyright © 2008 Free Tect Secrets ;) greatis just4fun network just4fun