简体   繁体   中英

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

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

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'.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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