TryEnterCriticalSection


static bool TryEnterCriticalSection(Handle Section)

This function attempts to gain ownership of a critical section.

Parameters

Handle Section

A pointer to the critical section whose ownership is being waited upon.

Return

bool

true Ownership of the critical section was granted.
false Ownership of the critical section was not granted.

Notes

The threads of a process may use a critical section object for mutual-exclusion synchronization. The process is responsible for allocating the memory used by a critical section object. This may be done by declaring an instance of the class CriticalSection. To initialize the object prior to making use of it, a thread of the process must call the function:

To enable mutually exclusive access to a shared resource, each thread calls this function or the function EnterCriticalSection to request ownership of the critical section. The difference between this function and the function EnterCriticalSection, is that the latter waits for ownership whilst this function effects an immediate return. When the thread has finished executing the protected code, it calls the function LeaveCriticalSection to relinquish ownership. This enables other threads to become the owner.

Once a thread has taken ownership of a critical section, it can make additional calls to EnterCriticalSection or TryEnterCriticalSection without blocking its execution. This prevents a thread from deadlocking itself while waiting for a critical section that it already owns.

The function LeaveCriticalSection must be called once for each time that the critical section was entered. The thread enters the critical section each time EnterCriticalSection or TryEnterCriticalSection succeeds.

To release the system resources that were allocated when the critical section object was initialized, the function DeleteCriticalSection may be called by any thread of the process. After it has been called, the critical section object can no longer be used for synchronization.

If a thread terminates while it has ownership of a critical section, the state of the critical section is undefined.

Details

Name Space IPlusPlus::Control
Class Base
Assembly IPlusPlus.WinPlus.dll