본문 바로가기
반응형

💻 programming67

[c++] condition variable (조건 변수) condition variable (조건 변수)를 사용하면 c++에서 멀티스레드 간 동기화를 구현할 수 있다 그렇지만 condition variable을 사용하는 것보다는, packaged task나 async와 같이 c++에서 제공하는 task를 이용하는 것이 멀티스레드 간 동기화를 안정적으로 구현하는 방법이라는 점을 명심하자 2021.08.04 - [c++/library] - [c++] thread vs task (thread 와 async) 2020/12/15 - [c++ language/library] - [c++] future 2020/12/15 - [c++ language/library] - [c++] packaged task 2020/12/15 - [c++ language/library] -.. 2020. 12. 17.
[c++] Mediator Pattern 중재자 패턴을 사용하면 객체 간 통신은 중재자 객체 안에 함축됩니다. 객체들은 더 이상 다른 객체와 서로 직접 통신하지 않으며 대신 중재자를 통해 통신합니다. 이를 통해 통신 객체 간 의존성을 줄일 수 있으므로 결합도를 감소시킬 수 있습니다. Class Diagram Colleage는 Mediator를 참조하고, Mediator는 Colleage를 참조하고 있습니다. Pros. and Cons. 장점: 전체적인 연결관계를 이해하기 쉽다 (communication의 흐름을 이해하기 쉽다) 단점: 특정 application 로직에 맞춰져있기 때문에 다른 application에 재사용하기 힘들다 (Observer Pattern과 반대) 무엇보다도 하나의 클래스가 여러 객체를 관리하는 형태를 가지므로 신 (Go.. 2020. 12. 16.
[c++] Visitor Pattern 객체 지향 프로그래밍과 소프트웨어 공학에서 비지터 패턴(visitor pattern; 방문자 패턴)은 알고리즘을 객체 구조에서 분리시키는 디자인 패턴입니다. 이렇게 분리를 하면 구조를 수정하지 않고도 실질적으로 새로운 동작을 기존의 객체 구조에 추가할 수 있게 됩니다. 개방-폐쇄 원칙을 적용하는 방법의 하나에 해당합니다. ko.wikipedia.org/wiki/%EB%B9%84%EC%A7%80%ED%84%B0_%ED%8C%A8%ED%84%B4 비지터 패턴 - 위키백과, 우리 모두의 백과사전 위키백과, 우리 모두의 백과사전. 둘러보기로 가기 검색하러 가기 ko.wikipedia.org 앞서 말한 것처럼 비지터 패턴은 알고리즘과 객체 구조를 분리시키는 디자인 패턴입니다. 알고리즘을 변경하거나 추가하더라도 기.. 2020. 12. 16.
[c++] Observer Pattern ko.wikipedia.org/wiki/%EC%98%B5%EC%84%9C%EB%B2%84_%ED%8C%A8%ED%84%B4 옵서버 패턴 - 위키백과, 우리 모두의 백과사전 위키백과, 우리 모두의 백과사전. 옵서버 패턴(observer pattern)은 객체의 상태 변화를 관찰하는 관찰자들, 즉 옵저버들의 목록을 객체에 등록하여 상태 변화가 있을 때마다 메서드 등을 통해 객체 ko.wikipedia.org 옵저버 패턴(observer pattern)은 객체의 상태 변화를 관찰하는 관찰자들, 즉 옵저버들의 목록을 객체에 등록하여 상태 변화가 있을 때마다 메서드 등을 통해 객체가 직접 목록의 각 옵저버에게 통지하도록 하는 디자인 패턴입니다. 주로 분산 이벤트 핸들링 시스템을 구현하는 데 사용되며, 발행/구독 .. 2020. 12. 16.
[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::timed_mutex en.cppreference.com/w/cpp/thread/timed_mutex std::timed_mutex - cppreference.com class timed_mutex; (since C++11) The timed_mutex class is a synchronization primitive that can be used to protect shared data from being simultaneously accessed by multiple threads. In a manner similar to mutex, timed_mutex offers exclusive, non-recursive en.cppreference.com mutex와 비슷하게, timed_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.
반응형