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

断了今生、忘了曾经 提交于 2019-12-24 22:10:49

问题


For C/C++, is the PCRE library thread-safe? If PCRE is thread-safe, is there any problem in performance?


回答1:


Judging from the PCRE documentation:

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.

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.

All of this means that if you are careful, the answer is 'Yes, the PCRE library is thread-safe'.




回答2:


Little off-topic, but I recommend to have a look at RE2 (RE2 is thread-friendly)



来源:https://stackoverflow.com/questions/28738674/is-the-pcre-library-thread-safe-if-not-which-do-you-recommend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!