Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/thread/doc/glossary.xml @ 35

Last change on this file since 35 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 12.4 KB
Line 
1<?xml version="1.0" encoding="utf-8"?>
2<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
3  "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
4  <!ENTITY % thread.entities SYSTEM "entities.xml">
5  %thread.entities;
6]>
7<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
8     Subject to the Boost Software License, Version 1.0.
9     (See accompanying file LICENSE-1.0 or  http://www.boost.org/LICENSE-1.0)
10-->
11<glossary id="thread.glossary" last-revision="$Date: 2006/10/15 14:52:53 $">
12  <title>Glossary</title>
13  <para>Definitions are given in terms of the C++ Standard
14  &cite.ISO98;. References to the standard are in the form [1.2.3/4], which
15  represents the section number, with the paragraph number following the
16  "/".</para>
17  <para>Because the definitions are written in something akin to "standardese",
18  they can be difficult to understand. The intent isn't to confuse, but rather
19  to clarify the additional requirements &Boost.Thread; places on a C++
20  implementation as defined by the C++ Standard.</para>
21  <glossentry id="thread.glossary.thread">
22    <glossterm>Thread</glossterm>
23    <glossdef>
24          <para>Thread is short for "thread of execution". A thread of execution is
25          an execution environment [1.9/7] within the execution environment of a C++
26          program [1.9]. The main() function [3.6.1] of the program is the initial
27          function of the initial thread. A program in a multithreading environment
28          always has an initial thread even if the program explicitly creates no
29          additional threads.</para>
30      <para>Unless otherwise specified, each thread shares all aspects of its
31          execution environment with other threads in the program. Shared aspects of
32          the execution environment include, but are not limited to, the
33          following:</para>
34          <itemizedlist>
35        <listitem><para>Static storage duration (static, extern) objects
36                [3.7.1].</para></listitem>
37            <listitem><para>Dynamic storage duration (heap) objects [3.7.3]. Thus
38                each memory allocation will return a unique addresses, regardless of the
39                thread making the allocation request.</para></listitem>
40        <listitem><para>Automatic storage duration (stack) objects [3.7.2]
41                accessed via pointer or reference from another thread.</para></listitem>
42        <listitem><para>Resources provided by the operating system. For example,
43                files.</para></listitem>
44        <listitem><para>The program itself. In other words, each thread is
45                executing some function of the same program, not a totally different
46                program.</para></listitem>
47      </itemizedlist>
48      <para>Each thread has its own:</para>
49      <itemizedlist>
50        <listitem><para>Registers and current execution sequence (program
51                counter) [1.9/5].</para></listitem>
52        <listitem><para>Automatic storage duration (stack) objects
53                [3.7.2].</para></listitem>
54      </itemizedlist>
55    </glossdef>
56  </glossentry>
57  <glossentry id="thread.glossary.thread-safe">
58    <glossterm>Thread-safe</glossterm>
59        <glossdef>
60      <para>A program is thread-safe if it has no <link
61          linkend="thread.glossary.race-condition">race conditions</link>, does
62          not <link linkend="thread.glossary.deadlock">deadlock</link>, and has
63          no <link linkend="thread.glossary.priority-failure">priority
64          failures</link>.</para>
65          <para>Note that thread-safety does not necessarily imply efficiency, and
66          than while some thread-safety violations can be determined statically at
67          compile time, many thread-safety errors can only only be detected at
68          runtime.</para>
69        </glossdef>
70  </glossentry>
71  <glossentry id="thread.glossary.thread-state">
72    <glossterm>Thread State</glossterm>
73        <glossdef>
74      <para>During the lifetime of a thread, it shall be in one of the following
75          states:</para>
76          <table>
77                <title>Thread States</title>
78                <tgroup cols="2" align="left">
79                        <thead>
80                                <row>
81                                        <entry>State</entry>
82                                        <entry>Description</entry>
83                                </row>
84                        </thead>
85                        <tbody>
86                                <row>
87                                        <entry>Ready</entry>
88                                        <entry>Ready to run, but waiting for a processor.</entry>
89                                </row>
90                                <row>
91                                        <entry>Running</entry>
92                                        <entry>Currently executing on a processor. Zero or more threads
93                                        may be running at any time, with a maximum equal to the number of
94                                        processors.</entry>
95                                </row>
96                                <row>
97                                        <entry>Blocked</entry>
98                                        <entry>Waiting for some resource other than a processor which is
99                                        not currently available, or for the completion of calls to library
100                                        functions [1.9/6]. The term "waiting" is synonymous with
101                                        "blocked"</entry>
102                                </row>
103                                <row>
104                                        <entry>Terminated</entry>
105                                        <entry>Finished execution but not yet detached or joined.</entry>
106                                </row>
107                        </tbody>
108                </tgroup>
109          </table>
110      <para>Thread state transitions shall occur only as specified:</para>
111          <table>
112                <title>Thread States Transitions</title>
113                <tgroup cols="3" align="left">
114                        <thead>
115                                <row>
116                                        <entry>From</entry>
117                                        <entry>To</entry>
118                                        <entry>Cause</entry>
119                                </row>
120                        </thead>
121                        <tbody>
122                                <row>
123                                        <entry>[none]</entry>
124                                        <entry>Ready</entry>
125                                        <entry><para>Thread is created by a call to a library function.
126                                        In the case of the initial thread, creation is implicit and
127                                        occurs during the startup of the main() function [3.6.1].</para></entry>
128                                </row>
129                                <row>
130                                        <entry>Ready</entry>
131                                        <entry>Running</entry>
132                                        <entry><para>Processor becomes available.</para></entry>
133                                </row>
134                                <row>
135                                        <entry>Running</entry>
136                                        <entry>Ready</entry>
137                                        <entry>Thread preempted.</entry>
138                                </row>
139                                <row>
140                                        <entry>Running</entry>
141                                        <entry>Blocked</entry>
142                                        <entry>Thread calls a library function which waits for a resource or
143                                        for the completion of I/O.</entry>
144                                </row>
145                                <row>
146                                        <entry>Running</entry>
147                                        <entry>Terminated</entry>
148                                        <entry>Thread returns from its initial function, calls a thread
149                                        termination library function, or is canceled by some other thread
150                                        calling a thread termination library function.</entry>
151                                </row>
152                                <row>
153                                        <entry>Blocked</entry>
154                                        <entry>Ready</entry>
155                                        <entry>The resource being waited for becomes available, or the
156                                        blocking library function completes.</entry>
157                                </row>
158                                <row>
159                                        <entry>Terminated</entry>
160                                        <entry>[none]</entry>
161                                        <entry>Thread is detached or joined by some other thread calling the
162                                        appropriate library function, or by program termination
163                                        [3.6.3].</entry>
164                                </row>
165                        </tbody>
166                </tgroup>
167      </table>
168      <para>[Note: if a suspend() function is added to the threading library,
169          additional transitions to the blocked state will have to be added to the
170          above table.]</para>
171    </glossdef>
172  </glossentry>
173  <glossentry id="thread.glossary.race-condition">
174    <glossterm>Race Condition</glossterm>
175        <glossdef>
176      <para>A race condition is what occurs when multiple threads read from and write
177          to the same memory without proper synchronization, resulting in an incorrect
178          value being read or written. The result of a race condition may be a bit
179          pattern which isn't even a valid value for the data type. A race condition
180          results in undefined behavior [1.3.12].</para>
181      <para>Race conditions can be prevented by serializing memory access using
182          the tools provided by &Boost.Thread;.</para>
183    </glossdef>
184  </glossentry>
185  <glossentry id="thread.glossary.deadlock">
186    <glossterm>Deadlock</glossterm>
187        <glossdef>
188      <para>Deadlock is an execution state where for some set of threads, each
189          thread in the set is blocked waiting for some action by one of the other
190          threads in the set. Since each is waiting on the others, none will ever
191          become ready again.</para>
192        </glossdef>
193  </glossentry>
194  <glossentry id="thread.glossary.starvation">
195    <glossterm>Starvation</glossterm>
196        <glossdef>
197          <para>The condition in which a thread is not making sufficient progress in
198          its work during a given time interval.</para>
199        </glossdef>
200  </glossentry>
201  <glossentry id="thread.glossary.priority-failure">
202    <glossterm>Priority Failure</glossterm>
203        <glossdef>
204          <para>A priority failure (such as priority inversion or infinite overtaking)
205          occurs when threads are executed in such a sequence that required work is not
206          performed in time to be useful.</para>
207        </glossdef>
208  </glossentry>
209  <glossentry id="thread.glossary.undefined-behavior">
210    <glossterm>Undefined Behavior</glossterm>
211        <glossdef>
212          <para>The result of certain operations in &Boost.Thread; is undefined;
213          this means that those operations can invoke almost any behavior when
214          they are executed.</para>
215         
216          <para>An operation whose behavior is undefined can work "correctly"
217          in some implementations (i.e., do what the programmer thought it
218          would do), while in other implementations it may exhibit almost
219          any "incorrect" behavior--such as returning an invalid value,
220          throwing an exception, generating an access violation, or terminating
221          the process.</para>
222         
223          <para>Executing a statement whose behavior is undefined is a
224          programming error.</para>
225        </glossdef>
226  </glossentry>
227  <glossentry id="thread.glossary.memory-visibility">
228    <glossterm>Memory Visibility</glossterm>
229        <glossdef>
230          <para>An address [1.7] shall always point to the same memory byte,
231          regardless of the thread or processor dereferencing the address.</para>
232      <para>An object [1.8, 1.9] is accessible from multiple threads if it is of
233          static storage duration (static, extern) [3.7.1], or if a pointer or
234          reference to it is explicitly or implicitly dereferenced in multiple
235          threads.</para>
236          <para>For an object accessible from multiple threads, the value of the
237          object accessed from one thread may be indeterminate or different from the
238          value accessed from another thread, except under the conditions specified in
239          the following table. For the same row of the table, the value of an object
240          accessible at the indicated sequence point in thread A will be determinate
241          and the same if accessed at or after the indicated sequence point in thread
242          B, provided the object is not otherwise modified. In the table, the
243          "sequence point at a call" is the sequence point after the evaluation of all
244          function arguments [1.9/17], while the "sequence point after a call" is the
245          sequence point after the copying of the returned value... [1.9/17].</para>
246      <table>
247                <title>Memory Visibility</title>
248                <tgroup cols="2">
249                        <thead>
250                                <row>
251                                        <entry>Thread A</entry>
252                                        <entry>Thread B</entry>
253                                </row>
254                        </thead>
255                        <tbody>
256                                <row>
257                                        <entry>The sequence point at a call to a library thread-creation
258                                        function.</entry>
259                                        <entry>The first sequence point of the initial function in the new
260                                        thread created by the Thread A call.</entry>
261                                </row>
262                                <row>
263                                        <entry>The sequence point at a call to a library function which
264                                        locks a mutex, directly or by waiting for a condition
265                                        variable.</entry>
266                                        <entry>The sequence point after a call to a library function which
267                                        unlocks the same mutex.</entry>
268                                </row>
269                                <row>
270                                        <entry>The last sequence point before thread termination.</entry>
271                                        <entry>The sequence point after a call to a library function which
272                                        joins the terminated thread.</entry>
273                                </row>
274                                <row>
275                                        <entry>The sequence point at a call to a library function which
276                                        signals or broadcasts a condition variable.</entry>
277                                        <entry>The sequence point after the call to the library function
278                                        which was waiting on that same condition variable or signal.</entry>
279                                </row>
280                        </tbody>
281                </tgroup>
282      </table>
283      <para>The architecture of the execution environment and the observable
284          behavior of the abstract machine [1.9] shall be the same on all
285          processors.</para>
286          <para>The latitude granted by the C++ standard for an implementation to
287          alter the definition of observable behavior of the abstract machine to
288          include additional library I/O functions [1.9/6] is extended to include
289          threading library functions.</para>
290          <para>When an exception is thrown and there is no matching exception handler
291          in the same thread, behavior is undefined. The preferred behavior is the
292          same as when there is no matching exception handler in a program
293          [15.3/9]. That is, terminate() is called, and it is implementation-defined
294          whether or not the stack is unwound.</para>
295    </glossdef>
296  </glossentry>
297  <section>
298    <title>Acknowledgements</title>
299    <para>This document was originally written by Beman Dawes, and then much
300        improved by the incorporation of comments from William Kempf, who now
301        maintains the contents.</para>
302        <para>The visibility rules are based on &cite.Butenhof97;.</para>
303  </section>
304</glossary>
Note: See TracBrowser for help on using the repository browser.