![](https://csdnimg.cn/release/download_crawler_static/87246574/bg4.jpg)
processing is often not the case, often between threads simultaneously
access some resources.Because access to shared resources causes conflict
is inevitable, in order to address this thread synchronization
problems,Win32 APIprovides a variety of synchronization objects to help
programmers access to shared resources to resolve the conflict.In
presenting these synchronization objects introduce wait functions before,
because all the control object's access control should use this function.
Win32 APIprovides a set of threads can block waiting for the
implementation of its own function.These functions in its argument object
generates one or more synchronization signal, or exceeds the waiting time
will be returned.Waiting function is not returned, the threads in a wait
state, when the thread consumes very littleCPUtime.Not only can
guarantee the wait function using thread synchronization, but also can
improve the running efficiency.Waiting function is the most commonly
used:
DWORD WaitForSingleObject(HANDLE hHandle,DWORD
dwMilliseconds);DWORD WaitForSingleObject (HANDLE hHandle,
DWORD dwMilliseconds);
The function can be used to simultaneously monitor
multipleWaitForMultipleObjectsynchronization object, the function is
declared as:
DWORD WaitForMultipleObject(DWORD nCount,CONST
HANDLE
*lpHandles,BOOLbWaitAll,DWORDdwMilliseconds);DWORD
WaitForMultipleObject (DWORD nCount, CONST HANDLE *
lpHandles, BOOL bWaitAll, DWORD dwMilliseconds);
(1)mutex object
Mutexstate of the object by any thread in that it does not have a time
signal, it was a time when no signal.Mutexobjects are suitable for
coordination of multiple threads exclusive access to shared resources.The
following steps can use the object: