System.SyncObjs.TMutex.Create

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

constructor Create(UseCOMWait: Boolean = False); overload;
constructor Create(MutexAttributes: PSecurityAttributes; InitialOwner: Boolean; const Name: string; UseCOMWait: Boolean = False); overload;
constructor Create(DesiredAccess: Cardinal; InheritHandle: Boolean; const Name: string; UseCOMWait: Boolean = False); overload;

C++

__fastcall TMutex(bool UseCOMWait)/* overload */;
__fastcall TMutex(Winapi::Windows::PSecurityAttributes MutexAttributes, bool InitialOwner, const System::UnicodeString Name, bool UseCOMWait)/* overload */;
__fastcall TMutex(unsigned DesiredAccess, bool InheritHandle, const System::UnicodeString Name, bool UseCOMWait)/* overload */;

Properties

Type Visibility Source Unit Parent
constructor public
System.SyncObjs.pas
System.SyncObjs.hpp
System.SyncObjs TMutex

Description

Instantiates a TMutex object.

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 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.


The third 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.

See Also