blob: 73c94b13fe9ebd97dcb6b97d9d9a6919251711f6 [file] [log] [blame]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Thread Safety</title>
<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
<link rel="home" href="../../index.html" title="Boost.Regex">
<link rel="up" href="../background_information.html" title="Background Information">
<link rel="prev" href="locale.html" title="Localization">
<link rel="next" href="examples.html" title="Test and Example Programs">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<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>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_regex.background_information.thread_safety"></a><a class="link" href="thread_safety.html" title="Thread Safety"> Thread
Safety</a>
</h3></div></div></div>
<p>
The Boost.Regex library is thread safe when Boost is: you can verify that
Boost is in thread safe mode by checking to see if <code class="computeroutput"><span class="identifier">BOOST_HAS_THREADS</span></code>
is defined: this macro is set automatically by the config system when threading
support is turned on in your compiler.
</p>
<p>
Class <a class="link" href="../ref/basic_regex.html" title="basic_regex"><code class="computeroutput"><span class="identifier">basic_regex</span></code></a>
and its typedefs regex and wregex are thread safe, in that compiled regular
expressions can safely be shared between threads. The matching algorithms
<a class="link" href="../ref/regex_match.html" title="regex_match"><code class="computeroutput"><span class="identifier">regex_match</span></code></a>,
<a class="link" href="../ref/regex_search.html" title="regex_search"><code class="computeroutput"><span class="identifier">regex_search</span></code></a>,
and <a class="link" href="../ref/regex_replace.html" title="regex_replace"><code class="computeroutput"><span class="identifier">regex_replace</span></code></a>
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,
in that the results of a match can be safely copied from one thread to another
(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,
while another thread pops them off the other end), otherwise use a separate
instance of <a class="link" href="../ref/match_results.html" title="match_results"><code class="computeroutput"><span class="identifier">match_results</span></code></a>
per thread.
</p>
<p>
The <a class="link" href="../ref/posix.html" title="POSIX Compatible C API's">POSIX API functions</a> are
all re-entrant and thread safe, regular expressions compiled with regcomp
can also be shared between threads.
</p>
<p>
The <a class="link" href="../ref/deprecated_interfaces/old_regex.html" title="High Level Class RegEx (Deprecated)">class
RegEx</a> is only thread safe if each thread gets its own RegEx instance
(apartment threading) - this is a consequence of RegEx handling both compiling
and matching regular expressions.
</p>
<p>
Finally note that changing the global locale invalidates all compiled regular
expressions, therefore calling <code class="computeroutput"><span class="identifier">set_locale</span></code>
from one thread while another uses regular expressions will produce unpredictable
results.
</p>
<p>
There is also a requirement that there is only one thread executing prior
to the start of main().
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 1998 -2010 John Maddock<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
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>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<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>
</div>
</body>
</html>