C++ - how does Sleep() and cin work?

后端 未结 7 1864
独厮守ぢ
独厮守ぢ 2021-02-05 10:38

Just curious. How does actually the function Sleep() work (declared in windows.h)? Maybe not just that implementation, but anyone. With that I mean - how is it implemented? How

7条回答
  •  攒了一身酷
    2021-02-05 11:06

    If you are looking for a more controlled way of blocking a thread/process in a multi-threaded program, have a look at Semaphores, Mutexes, CriticalSections and Events. These are all techniques used to block a process or thread (without loading the CPU via a while construct).

    They essentially work off of a Wait/Signal idiom where the blocked thread is waiting and another process signals it to tell it to start again. These (at least in windows) can also have timeouts, thus providing a similar functionality to Sleep().

提交回复
热议问题