3 <meta http-equiv=
"Content-Type" content=
"text/html; charset=US-ASCII">
4 <title>Thread Safety
</title>
5 <link rel=
"stylesheet" href=
"../../../../../../doc/src/boostbook.css" type=
"text/css">
6 <meta name=
"generator" content=
"DocBook XSL Stylesheets V1.77.1">
7 <link rel=
"home" href=
"../../index.html" title=
"Boost.Regex 5.1.2">
8 <link rel=
"up" href=
"../background_information.html" title=
"Background Information">
9 <link rel=
"prev" href=
"locale.html" title=
"Localization">
10 <link rel=
"next" href=
"examples.html" title=
"Test and Example Programs">
12 <body bgcolor=
"white" text=
"black" link=
"#0000FF" vlink=
"#840084" alink=
"#0000FF">
13 <table cellpadding=
"2" width=
"100%"><tr>
14 <td valign=
"top"><img alt=
"Boost C++ Libraries" width=
"277" height=
"86" src=
"../../../../../../boost.png"></td>
15 <td align=
"center"><a href=
"../../../../../../index.html">Home
</a></td>
16 <td align=
"center"><a href=
"../../../../../../libs/libraries.htm">Libraries
</a></td>
17 <td align=
"center"><a href=
"http://www.boost.org/users/people.html">People
</a></td>
18 <td align=
"center"><a href=
"http://www.boost.org/users/faq.html">FAQ
</a></td>
19 <td align=
"center"><a href=
"../../../../../../more/index.htm">More
</a></td>
22 <div class=
"spirit-nav">
23 <a accesskey=
"p" href=
"locale.html"><img src=
"../../../../../../doc/src/images/prev.png" alt=
"Prev"></a><a accesskey=
"u" href=
"../background_information.html"><img src=
"../../../../../../doc/src/images/up.png" alt=
"Up"></a><a accesskey=
"h" href=
"../../index.html"><img src=
"../../../../../../doc/src/images/home.png" alt=
"Home"></a><a accesskey=
"n" href=
"examples.html"><img src=
"../../../../../../doc/src/images/next.png" alt=
"Next"></a>
26 <div class=
"titlepage"><div><div><h3 class=
"title">
27 <a name=
"boost_regex.background_information.thread_safety"></a><a class=
"link" href=
"thread_safety.html" title=
"Thread Safety">Thread
29 </h3></div></div></div>
31 The Boost.Regex library is thread safe when Boost is: you can verify that
32 Boost is in thread safe mode by checking to see if
<code class=
"computeroutput"><span class=
"identifier">BOOST_HAS_THREADS
</span></code>
33 is defined: this macro is set automatically by the config system when threading
34 support is turned on in your compiler.
37 Class
<a class=
"link" href=
"../ref/basic_regex.html" title=
"basic_regex"><code class=
"computeroutput"><span class=
"identifier">basic_regex
</span></code></a>
38 and its typedefs regex and wregex are thread safe, in that compiled regular
39 expressions can safely be shared between threads. The matching algorithms
40 <a class=
"link" href=
"../ref/regex_match.html" title=
"regex_match"><code class=
"computeroutput"><span class=
"identifier">regex_match
</span></code></a>,
41 <a class=
"link" href=
"../ref/regex_search.html" title=
"regex_search"><code class=
"computeroutput"><span class=
"identifier">regex_search
</span></code></a>,
42 and
<a class=
"link" href=
"../ref/regex_replace.html" title=
"regex_replace"><code class=
"computeroutput"><span class=
"identifier">regex_replace
</span></code></a>
43 are all re-entrant and thread safe. Class
<a class=
"link" href=
"../ref/match_results.html" title=
"match_results"><code class=
"computeroutput"><span class=
"identifier">match_results
</span></code></a> is now thread safe,
44 in that the results of a match can be safely copied from one thread to another
45 (for example one thread may find matches and push
<a class=
"link" href=
"../ref/match_results.html" title=
"match_results"><code class=
"computeroutput"><span class=
"identifier">match_results
</span></code></a> instances onto a queue,
46 while another thread pops them off the other end), otherwise use a separate
47 instance of
<a class=
"link" href=
"../ref/match_results.html" title=
"match_results"><code class=
"computeroutput"><span class=
"identifier">match_results
</span></code></a>
51 The
<a class=
"link" href=
"../ref/posix.html" title=
"POSIX Compatible C API's">POSIX API functions
</a> are
52 all re-entrant and thread safe, regular expressions compiled with regcomp
53 can also be shared between threads.
56 The
<a class=
"link" href=
"../ref/deprecated_interfaces/old_regex.html" title=
"High Level Class RegEx (Deprecated)">class
57 RegEx
</a> is only thread safe if each thread gets its own RegEx instance
58 (apartment threading) - this is a consequence of RegEx handling both compiling
59 and matching regular expressions.
62 Finally note that changing the global locale invalidates all compiled regular
63 expressions, therefore calling
<code class=
"computeroutput"><span class=
"identifier">set_locale
</span></code>
64 from one thread while another uses regular expressions will produce unpredictable
68 There is also a requirement that there is only one thread executing prior
69 to the start of main().
72 <table xmlns:
rev=
"http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width=
"100%"><tr>
73 <td align=
"left"></td>
74 <td align=
"right"><div class=
"copyright-footer">Copyright
© 1998-
2013 John Maddock
<p>
75 Distributed under the Boost Software License, Version
1.0. (See accompanying
76 file LICENSE_1_0.txt or copy at
<a href=
"http://www.boost.org/LICENSE_1_0.txt" target=
"_top">http://www.boost.org/LICENSE_1_0.txt
</a>)
81 <div class=
"spirit-nav">
82 <a accesskey=
"p" href=
"locale.html"><img src=
"../../../../../../doc/src/images/prev.png" alt=
"Prev"></a><a accesskey=
"u" href=
"../background_information.html"><img src=
"../../../../../../doc/src/images/up.png" alt=
"Up"></a><a accesskey=
"h" href=
"../../index.html"><img src=
"../../../../../../doc/src/images/home.png" alt=
"Home"></a><a accesskey=
"n" href=
"examples.html"><img src=
"../../../../../../doc/src/images/next.png" alt=
"Next"></a>