Namespaces
Variants

std::shared_mutex:: try_lock

From cppreference.net

Concurrency support library
Threads
(C++11)
(C++20)
this_thread namespace
(C++11)
(C++11)
Cooperative cancellation
Mutual exclusion
Generic lock management
Condition variables
(C++11)
Semaphores
Latches and Barriers
(C++20)
(C++20)
Futures
(C++11)
(C++11)
(C++11)
Safe reclamation
Hazard pointers
Atomic types
(C++11)
(C++20)
Initialization of atomic types
(C++11) (deprecated in C++20)
(C++11) (deprecated in C++20)
Memory ordering
(C++11) (deprecated in C++26)
Free functions for atomic operations
Free functions for atomic flags
bool try_lock ( ) ;
(C++17 이후)

뮤텍스를 잠그려 시도합니다. 즉시 반환됩니다. 잠금 획득에 성공하면 true 를 반환하고, 그렇지 않으면 false 를 반환합니다.

이 함수는 허위로 실패할 수 있으며, 다른 스레드에 의해 현재 뮤텍스가 잠겨 있지 않은 경우에도 false 를 반환할 수 있습니다.

만약 try_lock 이 이미 mutex 를 어떤 모드(공유 또는 배타적)로든 소유하고 있는 스레드에 의해 호출되면, 그 동작은 정의되지 않습니다.

동일한 뮤텍스에 대한 이전 unlock() 연산은 이 연산이 true 를 반환할 경우 synchronizes-with (이 관계는 std::memory_order 에 정의된 대로) 합니다. 이전 lock() 연산은 이 연산이 false 를 반환할 경우 synchronize-with 관계를 형성하지 않습니다.

목차

매개변수

(없음)

반환값

true 락을 성공적으로 획득한 경우, 그렇지 않으면 false .

예외

아무것도 던지지 않습니다.

예제

참고 항목

뮤텍스를 잠금, 사용 가능하지 않으면 차단
(public member function)
뮤텍스를 잠금 해제
(public member function)
C documentation for mtx_trylock