blob: c23fe7e51e635cf164cea9d7259777292198b851 [file] [log] [blame]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Thread safety guarantees</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../intrusive.html" title="Chapter&#160;10.&#160;Boost.Intrusive">
<link rel="prev" href="value_traits.html" title="Containers with custom ValueTraits">
<link rel="next" href="obtaining_same_type_reducing_space.html" title="Obtaining the same types and reducing symbol length">
</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="value_traits.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../intrusive.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="obtaining_same_type_reducing_space.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="intrusive.thread_safety"></a><a class="link" href="thread_safety.html" title="Thread safety guarantees">Thread safety guarantees</a>
</h2></div></div></div>
<p>
Intrusive containers have thread safety guarantees similar to STL containers.
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
Several threads having read or write access to different instances is safe
as long as inserted objects are different.
</li>
<li class="listitem">
Concurrent read-only access to the same container is safe.
</li>
</ul></div>
<p>
Some Intrusive hooks (auto-unlink hooks, for example) modify containers without
having a reference to them: this is considered a write access to the container.
</p>
<p>
Other functions, like checking if an object is already inserted in a container
using the <code class="computeroutput"><span class="identifier">is_linked</span><span class="special">()</span></code>
member of safe hooks, constitute read access on the container without having
a reference to it, so no other thread should have write access (direct or indirect)
to that container.
</p>
<p>
Since the same object can be inserted in several containers at the same time
using different hooks, the thread safety of <span class="bold"><strong>Boost.Intrusive</strong></span>
is related to the containers and also to the object whose lifetime is manually
managed by the user.
</p>
<p>
As we can see, the analysis of the thread-safety of a program using <span class="bold"><strong>Boost.Intrusive</strong></span> is harder than with non-intrusive containers.
</p>
<p>
To analyze the thread safety, consider the following points:
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
The auto-unlink hook's destructor and <code class="computeroutput"><span class="identifier">unlink</span><span class="special">()</span></code> functions modify the container indirectly.
</li>
<li class="listitem">
The safe mode and auto-unlink hooks' <code class="computeroutput"><span class="identifier">is_linked</span><span class="special">()</span></code> functions are a read access to the container.
</li>
<li class="listitem">
Inserting an object in containers that will be modified by different threads
has no thread safety guarantee, although in most platforms it will be thread-safe
without locking.
</li>
</ul></div>
</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; 2005 Olaf Krzikalla, 2006-2010 Ion Gaztanaga<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="value_traits.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../intrusive.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="obtaining_same_type_reducing_space.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>