Condividi tramite


CMutex::CMutex

Constructs a named or unnamed CMutex object.

CMutex(
   BOOL bInitiallyOwn = FALSE,
   LPCTSTR lpszName = NULL,
   LPSECURITY_ATTRIBUTES lpsaAttribute = NULL 
);

Parameters

  • bInitiallyOwn
    Specifies if the thread creating the CMutex object initially has access to the resource controlled by the mutex.

  • lpszName
    Name of the CMutex object. If another mutex with the same name exists, lpszName must be supplied if the object will be used across process boundaries. If NULL, the mutex will be unnamed. If the name matches an existing mutex, the constructor builds a new CMutex object which references the mutex of that name. If the name matches an existing synchronization object that is not a mutex, the construction will fail.

  • lpsaAttribute
    Security attributes for the mutex object. For a full description of this structure, see SECURITY_ATTRIBUTES in the Windows SDK.

Remarks

To access or release a CMutex object, create a CMultiLock or CSingleLock object and call its Lock and Unlock member functions. If the CMutex object is being used stand-alone, call its Unlock member function to release it.

Security noteSecurity Note:

After creating the CMutex object, use GetLastError to ensure that the mutex did not already exist. If the mutex did exist unexpectedly, it may indicate a rogue process is squatting and may be intending to use the mutex maliciously. In this case, the recommended security-conscious procedure is to close the handle and continue as if there was a failure in creating the object.

Requirements

Header: afxmt.h

See Also

Concepts

CMutex Class

CMutex Members

Hierarchy Chart