是一个静态的boost :: wregex例如线程安全的? [英] Is a static boost::wregex instance thread-safe?
问题描述
它是安全的声明静态/全局变量有一个固定的boost :: wregex,然后从多个线程使用它而不用担心正则表达式的内部状态(如果加速已编译BOOST_HAS_THREADS)?
例如
的boost :: wregex g_regex(L共同|考);
再有多个线程调用:
如果(的boost :: regex_search(test_str,g_regex))
...
<一个href=\"http://www.boost.org/doc/libs/1_51_0/libs/regex/doc/html/boost_regex/background_information/thread_safety.html\" rel=\"nofollow\">http://www.boost.org/doc/libs/1_51_0/libs/regex/doc/html/boost_regex/background_information/thread_safety.html
<大段引用>
类basic_regex及其类型定义的正则表达式和wregex是线程安全的,在编制定期EX pressions可以安全地线程之间共享。匹配算法regex_match,regex_search和regex_replace都是重入和线程安全强>类的match_results现在线程安全的,在该匹配的结果可以从一个线程被安全地拷贝到另一个(例如一个线程可能会发现比赛和推动的match_results实例到一个队列,而另一个线程弹出它们赶走另一端),否则使用每个线程的match_results的一个单独的实例。
Is it safe to declare a static/global variable with a fixed boost::wregex and then use it from multiple threads without worrying about the regex's internal state (if Boost has been compiled with BOOST_HAS_THREADS)?
e.g.
boost::wregex g_regex( L"common|test" );
then have multiple threads calling:
if ( boost::regex_search( test_str, g_regex ) )
...
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.
这篇关于是一个静态的boost :: wregex例如线程安全的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!