Ñoordinating threads Part 3. Win32 objects. Mutex object.As I've already mentioned in the previous articles, all things that could be done with the VCL also could be done without it, using only Win32 API functions and services. Some VCL classes are only wrappers for appropriate Win32 objects, other add some functionality and service functions. Some Win32 objects are not implemented in the VCL but you still can use them calling Win32 API functions directly. So, let's look at the mutex object and create own VCL-style wrapper class. Win32 objects.All Win32 objects are opaque. Only Win32 subsystem "knows" an object internal structure and can access all the data an object contains directly. Win32 usually exports support routines that user-mode processes can call to manipulate an object. Object instance is accessed by HANDLE. You can think that a HANDLE is a unique value of type DWORD used by system to identify an object instance. CreateXXX API function returns a handle of newly created object. All of Win32 API functions, which are intended for manipulation of this type of objects, receive the object handle as actual parameter. CloseHandle function should be used to close object HANDLE. The object is destroyed when its last handle is closed. Each Win32 object could have a name. The name is limited to MAX_PATH (255) characters and can contain any character except the backslash path-separator character. Name comparison is case sensitive. All Win32 objects, such as mutexs, events, semaphores, memory-mapped files share the same name space. Mutex object."Mutex" is an abbreviation of "Mutual
Execution". The CreateMutex function creates named or
unnamed mutex object. HANDLE returned by CreateMutex can be used
in any function that requires a handle of a mutex object. Any
thread can call WaitForSingleObject function, which returns when
state of the mutex object is signaled. When a wait function
returns the waiting thread is released to continue its execution. Code.interface Code explanation.You can see that TILMutex is a simple wrapper for Win32 mutex object. Constructor Create creates a new named or unnamed mutex object depending on Name parameter using CreateMutex API function. TILMutex.Destroy closes mutex's handle using CloseHandle. Lock method tries to obtain ownership using WaitForSingleObject, and
The copyright of the article Ñoordinating threads Part 3. Win32 objects. Mutex object. in Delphi Programming is owned by Lyapin Ilya. Permission to republish Ñoordinating threads Part 3. Win32 objects. Mutex object. in print or online must be granted by the author in writing.
Go To Page: 1 2 Articles in this Topic Discussions in this Topic |