is the map find thread-safe?

Source: Internet
Author: User

Test environment gcc4.8.2

??

Iterator Find (const key_type& k);

Const_iterator Find (const key_type& k) const;

??

Unordered_map has two corresponding find functions I infer that the second one is safe and the first one is not thread safe.

??

Auto iter = _map.find (key)

Core in OpenMP multithreaded environment, thanks to Glog for error message output

??

***? aborted?at?1412933723? (unix?time)? Try? " [Email protected] "? if?you?are?using? gnu?date?***

Pc:[email protected]??????????? 0x8d1d65?std::equal_to<>::operator () ()

***? SIGSEGV? (@0x8)? Received?by? pid?3216? (tid?0x7f7c3902d700)? From? pid?8;? stack?trace:?***

[Email protected]????? 0x7f7c4b769150? (unknown)

[Email protected]??????????? 0x8d1d65?std::equal_to<>::operator () ()

[Email protected]??????????? 0x8e231b?std::__detail::_equal_helper<>::_s_equals ()

[Email protected]??????????? 0x8dbbb0?std::__detail::_hashtable_base<>::_m_equals ()

[Email protected]??????????? 0x8d1e63?std::_hashtable<>::_m_find_before_node ()

[Email protected]??????????? 0x8c432e?std::_hashtable<>::_m_find_node ()

[Email protected]??????????? 0x8b2bca?std::_hashtable<>::find ()

[Email protected]??????????? 0x89adcd?std::unordered_map<>::find ()

[Email protected]??????????? 0x87af21?gezi::lrumap<>::find ()

[Email protected]??????????? 0x85c6ab?gezi::timermap<>::count ()

[Email protected]??????????? 0x7ee705?run ()

[Email protected]??????????? 0x7f1893?_z3runv._omp_fn.3

[Email protected]????? 0x7f7c4a65641a?gomp_thread_start

[Email protected]????? 0x7f7c4b7611c1?start_thread

[Email protected]????? 0x7f7c49b6c0ad?__clone

Segmentation?fault

??

??

Since I may need to modify iter->second, I cannot use const_iterator

Increase

Iterator Iter;

#pragma omp critical

iter = _map.find (key);

??

The program is running normally.

is the map find thread-safe?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.