본문 바로가기
반응형

mutex4

[c++] std::shared_mutex en.cppreference.com/w/cpp/thread/shared_mutex std::shared_mutex - cppreference.com class shared_mutex; (since C++17) The shared_mutex class is a synchronization primitive that can be used to protect shared data from being simultaneously accessed by multiple threads. In contrast to other mutex types which facilitate exclusive access, a sh en.cppreference.com 상호배타적인 다른 mutex들과 달리 shard_mutex는 공유 자.. 2020. 12. 16.
[c++] std::recursive_mutex (std::mutex 비교) 일반적으로 mutex의 lock을 두 번 호출하면 무한 대기 상태에 빠지지만, recursive mutex는 lock을 여러 번 호출해도 문제가 없다 lock을 호출하는 동안은 계속 소유권을 가지고 있다가 lock을 호출한 횟수 만큼 unlock을 호출하면 소유권을 해제하기 때문이다 재귀함수를 만들어보면 쉽게 이해할 수 있다 (이름부터 recursive_mutex) 한 번 재귀함수를 병렬처리해보자 그냥 mutex를 사용했을 때 (무한 대기) worker 함수를 호출하는 4개의 스레드를 생성한다 worker 함수는 자기 자신을 다시 호출하는 재귀 함수로 구성한다 result라는 공유자원에 다른 스레드가 접근하지 못하도록 mutex lock을 수행한다 worker 내부에서 worker 함수를 다시 호출하므로.. 2020. 12. 16.
[c++] std::mutex en.cppreference.com/w/cpp/thread/mutex std::mutex - cppreference.com class mutex; (since C++11) The mutex class is a synchronization primitive that can be used to protect shared data from being simultaneously accessed by multiple threads. mutex offers exclusive, non-recursive ownership semantics: A calling thread owns a mut en.cppreference.com mutex는 여러 스레드의 공유 자원을 보호하기 위해 사용되는 클래스입니다. std::mute.. 2020. 12. 16.
[c++] mutex, lock guard, unique lock, shared mutex, recursive mutex medium.com/swlh/c-mutex-write-your-first-concurrent-code-69ac8b332288 [C++] MUTEX: Write Your First Concurrent Code Learn to design concurrent code and to protect shared with a mutex by implementing your first thread-safe queue! medium.com Mutex가 뭘까? Mutex는 여러 스레드에서 동시에 접근할 수 있는 공유 자원의 소유권을 결정하는 모델이다 Mutex를 이용해 다른 스레드에서 이 공유 자원에 접근하지 못하게 막을 수 있다는 의미다 만약 스레드 A에서 lock을 호출하면 unlock이 수행될 때까지 다른 스레드 .. 2020. 12. 16.
반응형