是对POSIX regcomp和regexec线程?具体而言,在GNU libc的? [英] Are posix regcomp and regexec threadsafe? In specific, on GNU libc?
问题描述
两个独立的问题,在这里真的:我能否使用多线程程序的正则表达式没有锁定,如果是这样,我可以使用相同的regex_t在多个线程同一时间?我无法找到谷歌或联机帮助页的答案。
Two separate questions here really: Can I use regexes in a multithreaded program without locking and, if so, can I use the same regex_t at the same time in multiple threads? I can't find an answer on Google or the manpages.
推荐答案
<一个href=\"http://www.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html\">http://www.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html
2.9.1线程安全的。
2.9.1 Thread-Safety
本卷POSIX.1-2008定义的所有功能应是线程安全的,但下面的功能1不一定是线程安全的。
All functions defined by this volume of POSIX.1-2008 shall be thread-safe, except that the following functions1 need not be thread-safe.
...
regexec
和 regcomp
不在该列表,所以他们必须是线程安全的。
regexec
and regcomp
are not in that list, so they are required to be thread-safe.
参见:<一href=\"http://www.opengroup.org/onlinepubs/9699919799/functions/regcomp.html\">http://www.opengroup.org/onlinepubs/9699919799/functions/regcomp.html
理文的部分内容:
的接口被定义,以使匹配的子串rm_sp和rm_ep是在一个单独的regmatch_t结构,而不是在regex_t。这使得能够在几个上下文中同时使用一个单一的编译RE;在main()和信号处理,也许,或轻量进程的多个线程。
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.
这篇关于是对POSIX regcomp和regexec线程?具体而言,在GNU libc的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!