Domanda

I would like to write a program, where several worker threads should process different tasks with different priorities. Large tasks would be processed with low priority and small tasks with a very high priority.

In a perfect world I would simply set a different priority for each kind of task, but since it is more task types than priority levels available on Windows, I think i have to set the thread priorities dynamically.

I think there should be a main thread with highest priority, working as a kind of scheduler setting the priorities of the worker threads dynamically. But I wonder what actually happens on Windows, when I call SetThreadPriority() and especially how quick the priority change is taken into account by the OS.

Ideally I need to boost the priority of a 'small task thread' within < 1 ms. Is this possible? And is there any way to change the latency of the OS (if there is any) reacting on the priority change?

È stato utile?

Soluzione

The windows dispatcher (scheduler) is not a single process/thread; it is spread across the kernel. The dispatcher is generally triggered by the following events:

  1. Thread becomes ready for execution
  2. Thread leaves running state (e.g. quantum expires, wait state, or done)
  3. The thread's priority changes (e.g. SetThreadPriority)
  4. Processor affinity changes

I need to boost the priority of a 'small task thread' within < 1 ms. Is this possible?

According to 3: Yes, the dispatcher will reschedule immediately.

Ref.: Windows Internals Tour: Windows Processes, Threads and Memory, Microsoft Academic Club 2011

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top