RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TMutex.Create Constructor (Boolean)

Instantiates a TMutex object.

Pascal
constructor Create(UseCOMWait: Boolean = False); overload;
constructor Create(MutexAttributes: PSecurityAttributes; InitialOwner: Boolean; const Name: string; UseCOMWait: Boolean = False); overload;
constructor Create(DesiredAccess: LongWord; InheritHandle: Boolean; const Name: string; UseCOMWait: Boolean = False); overload;
C++
__fastcall TMutex(Boolean UseCOMWait = False);
__fastcall TMutex(PSecurityAttributes MutexAttributes, Boolean InitialOwner, const AnsiString Name, Boolean UseCOMWait = False);
__fastcall TMutex(LongWord DesiredAccess, Boolean InheritHandle, const AnsiString Name, Boolean UseCOMWait = False);

Call Create to create a TMutex object.  

The first version of the constructor creates an unnamed mutex with the default security descriptor, and it establishes that the thread that created the mutex is not its initial owner. Set the UseCOMWait parameter to ensure that when a thread is blocked and waiting for the object, any STA COM calls can be made back into this thread.  

The second version of the constructor allows opening an existing mutex, identified by its name. The parameters have the following meaning:

Parameter  
Meaning  
DesiredAccess  
The type of access to the mutex. The constructor fails if the requested type of access is not permitted. It can be any combination of the following constants: MUTEX_ALL_ACCESS, MUTEX_MODIFY_STATE, SYNCHRONIZE, _DELETE, READ_CONTROL, WRITE_DAC, WRITE_OWNER. Any combination must include the SYNCHRONIZE access right, since this is specific to a mutex.  
InheritHandle  
Set this parameter for the child processes to inherit the mutex handle.  
Name  
The name of the mutex to open. Names are case-sensitive.  
UseCOMWait  
Set this parameter to ensure that when a thread is blocked and waiting for the object, any STA COM calls can be made back into this thread.  

 

The third version of the constructor creates a named mutex with several attributes, given through the following list of parameters:

Parameter  
Meaning  
MutexAttributes  
The security attributes of the mutex. MutexAttributes is of a pointer type to a _SECURITY_ATTRIBUTES record, with the following fields: nLength, lpSecurityDescriptor, InheritHandle.
The nLength field should always be equal to the size, in bytes, of the _SECURITY_ATTRIBUTES record. lpSecurityDescriptor is a pointer to the security descriptor of the mutex. Finally, InheritHandle is True if the handle to the mutex is to be inherited by child processes.  
InitialOwner  
Set this for the thread that created the mutex to be considered the initial owner of the mutex.  
Name  
The name of the mutex. Names are case-sensitive.  
UseCOMWait  
Set this parameter to ensure that when a thread is blocked and waiting for the object, any STA COM calls can be made back into this thread.  

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!