Does WaitForSingleObject give up a thread's time slice?

社会主义新天地 提交于 2019-11-29 10:59:30

Yes -- the thread is blocked until whatever it's waiting on becomes signaled. The thread won't be scheduled to run while it's blocked, so other threads get all the CPU time.

Note that time slices don't enter into it much though. A thread can give up execution in the middle of a time slice, and (for example) if what it's waiting on becomes signaled quickly, it might start executing again before its original time slice expires. When something is signaled, a thread that's waiting on it can wake up immediately, not necessarily waiting for the end of a time slice (e.g., if the thread that was waiting has higher priority than the thread that was running).

If the object you're waiting on is not already signalled, the thread will yield the rest of its timeslice and go to sleep until the object is signalled.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!