RtlTryEnterCriticalSection - NtDoc

Native API online documentation, based on the System Informer (formerly Process Hacker) phnt headers
#ifndef _NTRTL_H

/**
 * The RtlTryEnterCriticalSection routine attempts to enter a critical section without blocking the calling thread.
 *
 * \param CriticalSection A pointer to the critical section object.
 * \return A nonzero value if the critical section was successfully entered, otherwise zero.
 * \remarks Acquisition by the owning thread increments recursion. Each successful enter/try-enter needs one leave on that thread. Try-enter FALSE does not acquire a level. A successful status or unlocked snapshot is not a lifetime guarantee for the lock storage.
 */
_When_(return != 0, _Acquires_exclusive_lock_(*CriticalSection))
NTSYSAPI
LOGICAL
NTAPI
RtlTryEnterCriticalSection(
    _Inout_ PRTL_CRITICAL_SECTION CriticalSection
    );

#endif

View code on GitHub

NtDoc

Attempts to enter the specified critical section object without blocking.

Related Win32 API

TryEnterCriticalSection maps directly to this function.

See also