大网数据广告活动
Windows 系统接口

Context Switches

· 52CE 我爱测

The scheduler maintains separate queues of executable threads for each priority level.

The scheduler maintains separate queues of executable threads for each priority level. These threads 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 was preempted or voluntarily yielded by the processor.
  2. If the thread remains in a ready state, place it at the end of the queue for its priority level.
  3. Find the highest priority queue that contains ready threads.
  4. Remove the thread at the head of the queue, restore its context, and resume execution.

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.

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 07/14/2025
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。