Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

Reader-writer locks in concurrent_map

mudhaniu
Beginner
1,480 Views

Hello,

I was trying to use tbb::concurrent_map, and was wondering does a mutable iterator provide exclusive access to the key (similar to concurrent_hash_map's accessor), and similarly a const_iterator shared read access? I was looking at the source code, and wasn't able to find such a capability, but I just wanted to be sure?

If not, to clarify, concurrent_map just protects its internal structure from concurrent modification, not necessarily the values themselves? In that case, I was thinking of simply adding a pthread_rwlock_t to my values and doing r/w locking manually- I was wondering if there is a better approach leveraging the concurrent_map's APIs?

Thank you!

0 Kudos
1 Solution
SeshaP_Intel
Moderator
1,416 Views

Hi,


Thank you for posting in Intel Communities.


Yes, you are correct. In tbb::concurrent_map, the mutable iterator does not provide exclusive access to the key.


Please refer to the below links for more information.

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

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


If you are looking for thread safety, you can use tbb::concurrent_hash_map which is designed for parallelism and provides built-in support for thread-safe access to the values which are stored in the map.

You can refer to the OneTBB Pro Textbook, page no:186 for more information.


Thanks and Regards,

Pendyala Sesha Srinivas


View solution in original post

0 Kudos
3 Replies
SeshaP_Intel
Moderator
1,417 Views

Hi,


Thank you for posting in Intel Communities.


Yes, you are correct. In tbb::concurrent_map, the mutable iterator does not provide exclusive access to the key.


Please refer to the below links for more information.

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

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


If you are looking for thread safety, you can use tbb::concurrent_hash_map which is designed for parallelism and provides built-in support for thread-safe access to the values which are stored in the map.

You can refer to the OneTBB Pro Textbook, page no:186 for more information.


Thanks and Regards,

Pendyala Sesha Srinivas


0 Kudos
mudhaniu
Beginner
1,387 Views

Oh ok, thank you for this answer!

0 Kudos
SeshaP_Intel
Moderator
1,362 Views

Hi,


Thanks for accepting our solution. If you need any additional information, please post a new question as this thread will no longer be monitored by Intel.


Thanks and Regards,

Pendyala Sesha Srinivas


0 Kudos
Reply