D
D
Daniel2018-10-18 05:42:32
C++ / C#
Daniel, 2018-10-18 05:42:32

How do the sleep functions work?

Interested in how they are implemented, are they really in a long cycle every 1/1000 .... 0 seconds check the time .

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jcmvbkbc, 2018-10-18
@jcmvbkbc

How the sleep functions work

In general, there are two main approaches - busy wait (waiting in a loop) and scheduler-based (using a scheduler). Which of them is used depends on the context and environment capabilities: there are contexts in which the scheduler is not available (for example, a hardware interrupt handler in the OS kernel), there is cooperative multitasking, in which the scheduler cannot guarantee that the process will resume execution after a given time, there are delays so small that the call to the scheduler does not make sense. In these cases use busy wait. With preemptive multitasking and high-precision timers, a scheduler can be used for sufficiently long delays. The linux kernel uses both of these approaches.

A
Armenian Radio, 2018-10-18
@gbg

Depends on the specific implementation.
On Windows, Sleep() stops the thread that called it for the desired number of thread scheduler cycles. And at this time, the processor simply executes other threads.
In DOS, Sleep() started a long loop, inside which the program did nothing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question