Turning off COW in GCC

后端 未结 1 653
暗喜
暗喜 2020-12-30 03:12

I\'ve known for a while that GCC uses COW (Copy-On-Write) for std::string, making it impossible to use std::string in a multi-threaded program. Bu

相关标签:
1条回答
  • 2020-12-30 03:58

    If you're going to pass a string across a thread boundary, do an explicit copy, in order to force it to be an independent string, then pass that across:

    std::string a="bob";
    std::string b(a.data(), a.length());
    

    It's annoying to have to do this at all spots where things cross threads, but in my opinion it's easier than vector<char>.

    0 讨论(0)
提交回复
热议问题