c++ - 静态 boost::wregex 实例是线程安全的吗?

标签 c++ boost

用固定的 boost::wregex 声明一个静态/全局变量然后在多个线程中使用它而不用担心正则表达式的内部状态(如果 Boost 是用 BOOST_HAS_THREADS 编译的)是否安全?

例如

boost::wregex g_regex( L"common|test" );

然后有多个线程调用:

if ( boost::regex_search( test_str, g_regex ) )
...

最佳答案

http://www.boost.org/doc/libs/1_51_0/libs/regex/doc/html/boost_regex/background_information/thread_safety.html

Class basic_regex and its typedefs regex and wregex are thread safe, in that compiled regular expressions can safely be shared between threads. The matching algorithms regex_match, regex_search, and regex_replace are all re-entrant and thread safe. Class match_results is now thread safe, in that the results of a match can be safely copied from one thread to another (for example one thread may find matches and push match_results instances onto a queue, while another thread pops them off the other end), otherwise use a separate instance of match_results per thread.

关于c++ - 静态 boost::wregex 实例是线程安全的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12263013/

相关文章:

c++ - boost 优先级队列,查看元素是否已经在队列中

c++ - 在 C++(和 MoveIt API)上将成员函数的 std::bind 作为参数传递时出现问题

c++ - 在 C++ 中使用 std::complex<T> 创建复无穷大

用于方法组和装饰器的 C++ SFINAE

c++ - 通过 boost::asio::tcp::ip 发送的大正文

c++ - 模板 shared_ptr 参数

Emacs 中的 C++ 函数签名提示?

c++ - 你如何在不打开文件的情况下检查文件是否存在于C++中?

c++ - 打印 STL 容器以进行批准测试的公约

java - 执行时间 : Boost Multi-precision vs Java BigInteger