map find 是线程安全的吗

测试环境gcc4.8.2

   

iterator find ( const key_type& k );

const_iterator find ( const key_type& k ) const;

   

Unordered_map有两个对应的find函数 我推断第二个是安全的,第一个经过实测不是线程安全

   

auto iter = _map.find(key)

在openmp多线程环境下出core,感谢glog的错误信息输出

   

*** Aborted at 1412933723 (unix time) try "date -d @1412933723" if you are using GNU date ***

PC: @           0x8d1d65 std::equal_to<>::operator()()

*** SIGSEGV (@0x8) received by PID 3216 (TID 0x7f7c3902d700) from PID 8; stack trace: ***

    @     0x7f7c4b769150 (unknown)

    @           0x8d1d65 std::equal_to<>::operator()()

    @           0x8e231b std::__detail::_Equal_helper<>::_S_equals()

    @           0x8dbbb0 std::__detail::_Hashtable_base<>::_M_equals()

    @           0x8d1e63 std::_Hashtable<>::_M_find_before_node()

    @           0x8c432e std::_Hashtable<>::_M_find_node()

    @           0x8b2bca std::_Hashtable<>::find()

    @           0x89adcd std::unordered_map<>::find()

    @           0x87af21 gezi::LruMap<>::find()

    @           0x85c6ab gezi::TimerMap<>::count()

    @           0x7ee705 run()

    @           0x7f1893 _Z3runv._omp_fn.3

    @     0x7f7c4a65641a gomp_thread_start

    @     0x7f7c4b7611c1 start_thread

    @     0x7f7c49b6c0ad __clone

Segmentation fault

   

   

由于我可能需要修改iter->second,因此不能改用const_iterator

增加

iterator iter;

#pragma omp critical

iter = _map.find(key);

   

程序运行正常了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值