INtime SDK Help
TryEnterCriticalSection (iwin32)
INtime SDK v7.1 > About INtime > Alternate APIs > iwin32 API > iwin32 API > TryEnterCriticalSection (iwin32)

Checks for a critical section to be free and then owns it. There is no waiting (see also EnterCriticalSection).

BOOLEAN TryEnterCriticalSection(
    LPCRITICAL_SECTION lpCriticalSection
);

Parameters

lpCriticalSection
Specifies the critical section object.

Remarks

You cannot call this function from a pure INtime thread.

The threads of a single process can use a critical section object for mutual-exclusion synchronization. The process allocates the memory used by a critical section object by declaring a variable of type CRITICAL_SECTION. Before using a critical section, some process thread must call InitializeCriticalSection to initialize the object.

To enable mutually exclusive use of a shared resource, each thread calls EnterCriticalSection or TryEnterCriticalSection to request ownership of the critical section before executing any section of code that uses the protected resource. The difference is that TryEnterCriticalSection immediately returns, regardless of whether it obtained ownership of the critical section, while EnterCriticalSection blocks until the thread can take ownership of the critical section. When it finishes executing the protected code, the thread uses LeaveCriticalSection to relinquish ownership, enabling another thread to become the owner and gain access to the protected resource. The thread must call LeaveCriticalSection once for each time it entered the critical section.

Any thread in the process can use DeleteCriticalSection to release system resources allocated when the critical section object was initialized. After this function is called, the critical section object cannot be used for synchronization.

If a thread terminates while it owns a critical section, the critical section's state is undefined.

Return Values

Non-zero
Success. The critical section is successfully entered or the current thread already owns the critical section.
0 (zero)
Failure. Another thread already owns the critical section.

Requirements

Versions Defined in Include Link to
INtime 3.0 intime/rt/include/winbase.h windows.h iwin32.lib

Note

This function operates in the real-time portion of your application.

See Also

DeleteCriticalSection, EnterCriticalSection, InitializeCriticalSection, LeaveCriticalSection, iwin32 API, iwin32 Overview