Multithread 之 wait
- Sleep
- void Sleep(
DWORD dwMilliseconds
);
- This function suspends the execution of the current thread for a specified
interval.
- Busy Loop
- 不断调用GetExitCodeThread(),直到其结果不再是STILL_ACTIVE
- 缺点:浪费CPU时间
- WaitForSingleObject
- DWORD WaitForSingleObject(
HANDLE hHandle,
DWORD dwMilliseconds
);
- This function returns when the specified object is in the signaled state or when
the time-out interval elapses.
- Objecs:
- Event
- Mutex
- Semaphore
- Process
- Thread :线程结束时,线程对象被激发(signaled state)。
- WaitForMultipleObjects
- DWORD WaitForMultipleObjects(
DWORD nCount,
CONST HANDLE* lpHandles,
BOOL fWaitAll,
DWORD dwMilliseconds
);
- This function returns a value when either any one of the specified objects is in
the signaled state, or the time-out interval elapses.
- MsgWaitForMultipleObjects
- 参考:《Win32多线程程序设计》
原文地址:https://www.cnblogs.com/dahai/p/2109577.html