Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/thread/doc/once-ref.xml @ 12

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

added boost

File size: 2.9 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 % threads.entities SYSTEM "entities.xml">
5  %threads.entities;
6]>
7<header name="boost/thread/once.hpp"
8        last-revision="$Date: 2004/07/17 04:33:59 $">
9        <macro name="BOOST_ONCE_INIT">
10                <purpose>The <functionname>call_once</functionname> function and
11                <code>once_flag</code> type (statically initialized to
12                <macroname>BOOST_ONCE_INIT</macroname>) can be used to run a
13                routine exactly once. This can be used to initialize data in a
14                <link linkend="threads.glossary.thread-safe">thread-safe</link>
15                manner.</purpose>
16               
17                <description>The implementation-defined macro
18                <macroname>BOOST_ONCE_INIT</macroname> is a constant value used to
19                initialize <code>once_flag</code> instances to indicate that the
20                logically associated routine has not been run yet. See
21                <functionname>call_once</functionname> for more details.</description>
22        </macro>
23               
24        <namespace name="boost">
25                <typedef name="once_flag">
26                        <purpose>The <functionname>call_once</functionname> function and
27                        <code>once_flag</code> type (statically initialized to
28                        <macroname>BOOST_ONCE_INIT</macroname>) can be used to run a
29                        routine exactly once. This can be used to initialize data in a
30                        <link linkend="threads.glossary.thread-safe">thread-safe</link>
31                        manner.</purpose>
32                       
33                        <description>The implementation-defined type <code>once_flag</code>
34                        is used as a flag to insure a routine is called only once.
35                        Instances of this type should be statically initialized to
36                        <macroname>BOOST_ONCE_INIT</macroname>. See
37                        <functionname>call_once</functionname> for more details.
38                        </description>
39
40                        <type><emphasis>implementation-defined</emphasis></type>
41                </typedef>
42
43                <function name="call_once">
44                        <purpose>The <functionname>call_once</functionname> function and
45                        <code>once_flag</code> type (statically initialized to
46                        <macroname>BOOST_ONCE_INIT</macroname>) can be used to run a
47                        routine exactly once. This can be used to initialize data in a
48                        <link linkend="threads.glossary.thread-safe">thread-safe</link>
49                        manner.</purpose>
50                       
51                        <description>
52                        <para>Example usage is as follows:</para>
53                        <para>
54<programlisting>//Example usage:
55boost::once_flag once = BOOST_ONCE_INIT;
56
57void init()
58{
59    //...
60}
61
62void thread_proc()
63{
64    boost::call_once(&amp;init, once);
65}</programlisting>
66                        </para></description>
67                       
68                        <parameter name="func">
69                                <paramtype>void (*func)()</paramtype>
70                        </parameter>
71                       
72                        <parameter name="flag">
73                                <paramtype>once_flag&amp;</paramtype>
74                        </parameter>
75                       
76                        <requires>The function <code>func</code> shall not throw
77                        exceptions.</requires>
78                       
79                        <effects>As if (in an atomic fashion):
80                        <code>if (flag == BOOST_ONCE_INIT) func();</code></effects>
81                       
82                        <postconditions><code>flag != BOOST_ONCE_INIT</code>
83                        </postconditions>
84                </function>
85        </namespace>
86</header>
Note: See TracBrowser for help on using the repository browser.