• 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);

       

    程序运行正常了

  • 相关阅读:
    Visual Studio Code 上java开发环境搭建
    c++编译时打印宏定义
    git使用
    Let's Encrypt申请证书及使用
    使用docker创建aosp编译环境
    项目中使用protobuf 3.0
    ubuntu14.04 安装mono
    ubuntu14.04 安装apache+mysql+php
    Discuz & UCenter 修改手记
    代码细节重构:请对我的代码指手划脚(四)
  • 原文地址:https://www.cnblogs.com/rocketfan/p/4017587.html
Copyright © 2020-2023  润新知