Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/thread/doc/once-ref.xml @ 29

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

updated boost from 1_33_1 to 1_34_1

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