Does WaitForSingleObject call a thread time span?

I am making a win32 program in C.

When you have many threads and one of the threads is waiting for an event (for example, using WaitForSingleObject() ), does this thread still get a full chunk of processor time?

In other words, does the operating system know that the thread does not need its temporary fragment until one of the events is reported?

+4
source share
2 answers

Yes - the stream is blocked until it is signaled that it is waiting. A thread will not be scheduled during its blocking, therefore other threads will receive all the time of the processor.

Note that temporary fragments are not included in it, though. A thread can refuse to execute in the middle of a time fragment and (for example), if what it expects is signaled quickly, it can start execution before its initial time slice expires. When something is signaled, a thread waiting for it can instantly wake up, not necessarily waiting for the end of the time fragment (for example, if the waiting thread has a higher priority than the thread that was started).

+8
source

If the object you are expecting is no longer signaled, the stream will give the remainder of its time and go into sleep mode until the object is signaled.

+2
source

Source: https://habr.com/ru/post/1247547/


All Articles