Win32 线程调度 [英] Win32 Thread scheduling

查看:39
本文介绍了Win32 线程调度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,Windows 线程调度程序不会区分属于两个不同进程的线程,前提是它们都具有相同的基本优先级.我的问题是,如果我有两个应用程序,一个只有一个线程,另一个有 50 个线程,所有线程都具有相同的基本优先级,这是否意味着第二个进程比第一个进程享受更多的 CPU 时间?

解决方案

Windows 中的调度处于线程粒度.这种方法背后的基本思想是进程不运行,而只提供资源和线程运行的上下文.回到你的问题,因为调度决策是严格基于线程做出的,所以没有考虑线程属于哪个进程.在您的示例中,如果进程 A 有 1 个可运行线程,进程 B 有 50 个可运行线程,并且所有 51 个线程的优先级相同,则每个线程将获得 1/51 的 CPU 时间——Windows 不会提供 50CPU 的百分比用于处理 A,50% 用于处理 B.要了解线程调度算法,您必须首先了解 Windows 使用的优先级级别.您可以参考此处以获取快速参考.>

尝试阅读 Windows Internals 以深入了解.

As I understand, windows thread scheduler does not discriminate beween threads belonging two different processes, provided all of them have the same base priority. My question is if I have two applications one with only one thread and the other with say 50 threads all with same base priority, does it mean that the second process enjoys more CPU time then the first one?

解决方案

Scheduling in Windows is at the thread granularity. The basic idea behind this approach is that processes don't run but only provide resources and a context in which their threads run. Coming back to your question, because scheduling decisions are made strictly on a thread basis, no consideration is given to what process the thread belongs to. In your example, if process A has 1 runnable thread and process B has 50 runnable threads, and all 51 threads are at the same priority, each thread would receive 1/51 of the CPU time—Windows wouldn't give 50 percent of the CPU to process A and 50 percent to process B. To understand the thread-scheduling algorithms, you must first understand the priority levels that Windows uses. You can refer here for quick reference.

Try reading Windows Internals for in depth understanding.

这篇关于Win32 线程调度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆