Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/thread/doc/glossary.xml @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

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