93 lines
5.4 KiB
HTML
93 lines
5.4 KiB
HTML
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|||
|
<html>
|
|||
|
<head>
|
|||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|||
|
<title>Thread safety guarantees</title>
|
|||
|
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
|
|||
|
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
|
|||
|
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
|
|||
|
<link rel="up" href="../intrusive.html" title="Chapter 19. Boost.Intrusive">
|
|||
|
<link rel="prev" href="value_traits.html" title="Containers with custom ValueTraits">
|
|||
|
<link rel="next" href="boost_intrusive_iterators.html" title="Boost.Intrusive Iterator features">
|
|||
|
</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="boost_intrusive_iterators.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" style="list-style-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" style="list-style-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 © 2005 Olaf Krzikalla<br>Copyright © 2006-2015 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="boost_intrusive_iterators.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
|
|||
|
</div>
|
|||
|
</body>
|
|||
|
</html>
|