c - posix regcomp 和 regexec 线程安全吗?具体来说,在 GNU libc 上?

标签 c regex pthreads posix libc

这里确实有两个不同的问题:我可以在多线程程序中使用正则表达式而不锁定吗?如果可以,我可以在多个线程中同时使用相同的 regex_t 吗?我在 Google 或联机帮助页上找不到答案。

最佳答案

http://www.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html

2.9.1 Thread-Safety

All functions defined by this volume of POSIX.1-2008 shall be thread-safe, except that the following functions1 need not be thread-safe.

...

regexecregcomp 不在该列表中,因此它们必须是线程安全的。

另请参阅:http://www.opengroup.org/onlinepubs/9699919799/functions/regcomp.html

部分理由文本如下:

The interface is defined so that the matched substrings rm_sp and rm_ep are in a separate regmatch_t structure instead of in regex_t. This allows a single compiled RE to be used simultaneously in several contexts; in main() and a signal handler, perhaps, or in multiple threads of lightweight processes.

关于c - posix regcomp 和 regexec 线程安全吗?具体来说,在 GNU libc 上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4404574/

相关文章:

c++ - C/C++ 中的执行顺序是否始终相同

php - 棘手的模式匹配

c - 为什么我的C多线程调度程序出现段错误(核心转储)

c - 指针类型与 PyArray_SimpleNew 不匹配

c - 如何从文本文件中读取整数和字符并将它们存储在单独的数组中?

java - 从 Java String 的末尾删除行尾字符

c++ - 多线程程序中的核心转储:basic_string::_S_construct null 无效

c - 使用条件变量的简单多线程堆栈实现

c - 从 sublime 2.02 运行 C 程序

c# - 不破坏 html c# 的子字符串