summaryrefslogtreecommitdiff
path: root/doc/html/intrusive/thread_safety.html
blob: ce3becefd1b22a129ad64357002722b11c170ff6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<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.76.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../intrusive.html" title="Chapter&#160;13.&#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<br>Copyright &#169; 2006-2012 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>