简体   繁体   English

PCRE库是线程安全的吗? 如果没有,您推荐哪个?

[英]Is the PCRE library thread-safe? If not, which do you recommend?

For C/C++, is the PCRE library thread-safe? 对于C / C ++, PCRE库是否是线程安全的? If PCRE is thread-safe, is there any problem in performance? 如果PCRE是线程安全的,性能是否存在问题?

Judging from the PCRE documentation: PCRE文档来看:

MULTITHREADING 多重阅读

The PCRE functions can be used in multi-threading applications, with the proviso that the memory management functions pointed to by pcre_malloc, pcre_free, pcre_stack_malloc, and pcre_stack_free, and the callout and stack-checking functions pointed to by pcre_callout and pcre_stack_guard, are shared by all threads. PCRE函数可以在多线程应用程序中使用,前提是pcre_malloc,pcre_free,pcre_stack_malloc和pcre_stack_free指向的内存管理函数以及pcre_callout和pcre_stack_guard指向的调出和堆栈检查函数由所有线程。

The compiled form of a regular expression is not altered during matching, so the same compiled pattern can safely be used by several threads at once. 正则表达式的编译形式在匹配期间不会更改,因此同一编译模式可以安全地一次被多个线程使用。

If the just-in-time optimization feature is being used, it needs separate memory stack areas for each thread. 如果使用即时优化功能,则每个线程需要单独的内存堆栈区域。 See the pcrejit documentation for more details. 有关更多详细信息,请参见pcrejit文档。

All of this means that if you are careful, the answer is 'Yes, the PCRE library is thread-safe'. 所有这些都意味着,如果您小心的话,答案是“是的,PCRE库是线程安全的”。

有点题外话,但我建议看看RE2 (RE2是线程友好的)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM