Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

As far as I can tell, both use:

  • Multilevel feedback queue
  • Priority levels (different range)
  • Both manage threads and not the process

But what are the big differences?

share|improve this question

migrated from stackoverflow.com Apr 20 '12 at 4:19

This question came from our site for professional and enthusiast programmers.

3 Answers 3

up vote 3 down vote accepted

According to Scheduling Priorities at MSDN:

Threads are scheduled to run based on their scheduling priority. Each thread is assigned a scheduling priority. The priority levels range from zero (lowest priority) to 31 (highest priority). Only the zero-page thread can have a priority of zero. (The zero-page thread is a system thread responsible for zeroing any free pages when there are no other threads that need to run.)

The system treats all threads with the same priority as equal. The system assigns time slices in a round-robin fashion to all threads with the highest priority. If none of these threads are ready to run, the system assigns time slices in a round-robin fashion to all threads with the next highest priority. If a higher-priority thread becomes available to run, the system ceases to execute the lower-priority thread (without allowing it to finish using its time slice), and assigns a full time slice to the higher-priority thread. The priority of each thread is determined by the following criteria:

  • The priority class of its process
  • The priority level of the thread within the priority class of its process

I believe this thread scheduler describes an algorithm called multilevel queue, which is a much simpler scheduling algorithm than multilevel feedback queue. Note that Windows' process scheduler uses multilevel feedback queue, according to Wikipedia. Since Windows 7 and Windows Server 2008 R2, there is also User-Mode Scheduling which lets processes manage their own threads scheduling.

As mentioned by others, Linux treats process and threads the same from scheduling perspective. Process/thread scheduling in Linux is configurable, there are various scheduling algorithms and some can be configured by recompiling the kernel:

Note that default above means default in vanilla kernel. Some distros ship with a default kernel that is preconfigured to use different default scheduler.

In addition to the scheduling algorithm, there are also scheduler policies: SCHED_FIFO, SCHED_BATCH, SCHED_IDLE, SCHED_OTHER, and SCHED_RR; which can be changed at runtime which describes the kind of workload that a process has.

The current default scheduler Completely Fair Scheduler, uses a red-black tree to maintain scheduling fairness. From Inside the Linux 2.6 Completely Fair Scheduler:

The main idea behind the CFS is to maintain balance (fairness) in providing processor time to tasks. This means processes should be given a fair amount of the processor. When the time for tasks is out of balance (meaning that one or more tasks are not given a fair amount of time relative to others), then those out-of-balance tasks should be given time to execute.

To determine the balance, the CFS maintains the amount of time provided to a given task in what's called the virtual runtime. The smaller a task's virtual runtime—meaning the smaller amount of time a task has been permitted access to the processor—the higher its need for the processor. The CFS also includes the concept of sleeper fairness to ensure that tasks that are not currently runnable (for example, waiting for I/O) receive a comparable share of the processor when they eventually need it.

But rather than maintain the tasks in a run queue, as has been done in prior Linux schedulers, the CFS maintains a time-ordered red-black tree (see Figure 1). A red-black tree is a tree with a couple of interesting and useful properties. First, it's self-balancing, which means that no path in the tree will ever be more than twice as long as any other. Second, operations on the tree occur in O(log n) time (where n is the number of nodes in the tree). This means that you can insert or delete a task quickly and efficiently.

So main differences:

Windows

  • Process scheduling using Multilevel feedback queue + Thread scheduling using Multilevel queue. The thread scheduler simply picks the highest priority thread, the process scheduler is smarter and uses feedback queue.

Linux

  • Unified process and thread scheduler, configurable, by default uses CFS. The scheduler uses a metric of fairness and uses priority to skew the distribution of CPU to higher priority processes.
share|improve this answer

If you are refering to the kernel scheduler (and not a periodic task scheduler like some comments suggest), in Linux is pretty easy: in terms of scheduling, Linux makes no difference between threads and processes. From the kernel point of view, they are just scheduling units; the difference relies in the weight of the context switch. This is sometimes called a one-to-one threading model.

As there is less information available regarding Windows internals, little can be said. However, Windows has historically differentiated between processes and threads so it is more likely that they are treated differently in terms of scheduling.

share|improve this answer

C2H5OH, Why would you say there's no documentation on Windows Internals when everything is available? Beats me... You can read the most of the basics here, http://msdn.microsoft.com/en-us/library/windows/desktop/ms684259(v=vs.85).aspx

There's an article on Wikipedia (Threads (computing)) which states most of the differences, but without cited sources, so...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["                  <li><a href=\"//area51.stackexchange.com\" title=\"proposing new sites in the Stack Exchange network\">Area 51</a></li>\r\n                        <li><a href=\"//careers.stackoverflow.com\">Stack Overflow Careers</a></li>\r\n                    \r\n                </ol>\r\n            </td>\r\n    </tr>\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &#169; 2015 stack exchange inc; user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc by-sa 3.0</a> \r\n                with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2015.4.24.2525\r\n            </div>\r\n            \r\n        </div>\r\n    </div>\r\n    <noscript>\r\n        <div id=\"noscript-warning\">Super User works best with JavaScript enabled<img src=\"http://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif\" alt=\"\" class=\"dno\"></div>\r\n    </noscrip"], "copyright__copyright__copyright": ["thing is available? Beats me... You can read the most of the basics here, http://msdn.microsoft.com/en-us/library/windows/desktop/ms684259(v=vs.85).aspx\n\nThere's an article on Wikipedia (Threads (computing)) which states most of the differences, but without cited sources, so...\n\nshare|improve this answer\n\nYour Answer\n\n\u00a0\ndiscard\n\nBy posting your answer, you agree to the privacy policy and terms of service.\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}