[Effective Modern C++] 항목 16. const 멤버 함수를 스레드에 안전하게 작성하라
멤버 함수가 멤버 변수들을 수정하지 않는다면 const 로 선언하는 것이 자연스럽다. 그런데 스레드를 사용한다면 문제가 생길 수 있다. 예시를 통해 살펴보자. mutex의 사용 다음은 다항식의 근을 구는 함수 roots 를 구현하는 상황이다. 성능 향상을 위해 캐싱을 이용하였으며, rootsAreValid 의 값을 이용하여 캐싱 여부를 판별하는 함수이다. class Polynomial { public: using RootsType = std::vector; RootsType roots() const { if(!rootsAreValid) { ... rootsAreValid = true; } } private: mutable bool rootsAreValid{ false }; mutable RootsType..
C++/Effective Modern C++
2019. 10. 30. 23:57
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- detach
- forward
- Modern
- auto
- 람다
- Forwarding
- 보편참조
- thread
- 발아시기
- Overloading
- C
- C++
- Perfect
- 보편 참조
- CPP
- std::forward
- 포인터
- Override
- std::move
- Future
- Effective
- C++14
- Effective Modern C++
- const
- 다이소
- Unreal
- MOVE
- Join
- C++11
- async
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
글 보관함