TBB 의 concurrent container 들은 쓰레드 안전할 것 같은 이름을 가졌지만 method 마다 쓰레드 안전성이 다를 수 있다.

concurrent_unordered_map 은 insert, lookup, traversal 은 동시에 할 수 있으나 erase 는 쓰레드 안전하지 않다.

https://spec.oneapi.io/versions/latest/elements/oneTBB/source/containers/concurrent_unordered_map_cls.html

 

concurrent_unordered_map — oneAPI Specification 1.2-provisional-rev-1 documentation

 

spec.oneapi.io

http://egloos.zum.com/sweeper/v/3053901

 

[TBB] concurrent_unordered_map/multimap

Reference page : TBB reference manual - concurrent_unordered_map 1. concurrent_unordered_map 1) 주요 특징 삽입과 이터레이션은 쓰레드 세이프하다.concurrent_hash_map과 다르게 [] 오퍼레이터와 at 함수를 제공하며, 쓰레드

egloos.zum.com

안전하지 않은 method 들은 unsafe_erase 처럼 unsafe 가 붙어 있다. clear, swap 도 unsafe 하다.

https://spec.oneapi.io/versions/latest/elements/oneTBB/source/containers/concurrent_unordered_map_cls/unsafe_modifiers.html

 

Concurrently unsafe modifiers — oneAPI Specification 1.2-provisional-rev-1 documentation

 

spec.oneapi.io

insert, lookup, traversal 이 안전하다고 해서 그 값을 동시에 접근해서 읽고 쓰는게 안전하다는 것도 아니다. 만약에  std::shared_ptr 같은 구조체를 사용한다면 c++ 20 이전에는 atomic_store, atomic_load 를 사용하고 c++ 20 부터는 atomic_shared_ptr 을 사용해야 한다.

boost::shared_ptr 같은 구조체를 사용한다면 차라리 accessor 라는 것을 통해 동시 접근 제어를 할 수 있는 concurrent_hash_map 을 사용하는 것도 방법이다. accessor 는 rw, const_accessor 는 r 접근할 때 사용한다. accessor 는 atomic 구조체로 구현된 spin_rw_mutex 를 이용해 bucket 접근을 제어한다.

https://spec.oneapi.io/versions/latest/elements/oneTBB/source/containers/concurrent_hash_map_cls.html

 

concurrent_hash_map — oneAPI Specification 1.2-provisional-rev-1 documentation

 

spec.oneapi.io

https://oneapi-src.github.io/oneTBB/main/tbb_userguide/concurrent_hash_map.html

 

concurrent_hash_map — oneTBB documentation

 

oneapi-src.github.io

http://egloos.zum.com/sweeper/v/3053914

 

[TBB] concurrent_hash_map

Reference page: TBB reference manual - concurrent_hash_map 1. 주요 특징 count, find, insert, erase 동작은 쓰레드 세이프하다.count, find, insert, erase는 기존의 iterator를 무효화시킬 수 있다.count, find, insert, erase를 제외

egloos.zum.com

 

728x90

+ Recent posts