File: once-ref.xml

package info (click to toggle)
boost 1.33.1-10
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 100,948 kB
  • ctags: 145,103
  • sloc: cpp: 573,492; xml: 49,055; python: 15,626; ansic: 13,588; sh: 2,099; yacc: 858; makefile: 660; perl: 427; lex: 111; csh: 6
file content (86 lines) | stat: -rw-r--r-- 2,984 bytes parent folder | download | duplicates (2)
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
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
  "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
  <!ENTITY % threads.entities SYSTEM "entities.xml">
  %threads.entities;
]>
<header name="boost/thread/once.hpp"
	last-revision="$Date: 2004/07/17 04:33:59 $">
	<macro name="BOOST_ONCE_INIT">
		<purpose>The <functionname>call_once</functionname> function and
		<code>once_flag</code> type (statically initialized to 
		<macroname>BOOST_ONCE_INIT</macroname>) can be used to run a
		routine exactly once. This can be used to initialize data in a
		<link linkend="threads.glossary.thread-safe">thread-safe</link>
		manner.</purpose>
		
		<description>The implementation-defined macro 
		<macroname>BOOST_ONCE_INIT</macroname> is a constant value used to 
		initialize <code>once_flag</code> instances to indicate that the 
		logically associated routine has not been run yet. See 
		<functionname>call_once</functionname> for more details.</description>
	</macro>
		
	<namespace name="boost">
		<typedef name="once_flag">
			<purpose>The <functionname>call_once</functionname> function and
			<code>once_flag</code> type (statically initialized to 
			<macroname>BOOST_ONCE_INIT</macroname>) can be used to run a
			routine exactly once. This can be used to initialize data in a
			<link linkend="threads.glossary.thread-safe">thread-safe</link>
			manner.</purpose>
			
			<description>The implementation-defined type <code>once_flag</code>
			is used as a flag to insure a routine is called only once.
			Instances of this type should be statically initialized to
			<macroname>BOOST_ONCE_INIT</macroname>. See 
			<functionname>call_once</functionname> for more details.
			</description>

			<type><emphasis>implementation-defined</emphasis></type>
		</typedef>

		<function name="call_once">
			<purpose>The <functionname>call_once</functionname> function and
			<code>once_flag</code> type (statically initialized to 
			<macroname>BOOST_ONCE_INIT</macroname>) can be used to run a
			routine exactly once. This can be used to initialize data in a
			<link linkend="threads.glossary.thread-safe">thread-safe</link>
			manner.</purpose>
			
			<description>
			<para>Example usage is as follows:</para>
			<para>
<programlisting>//Example usage:
boost::once_flag once = BOOST_ONCE_INIT;

void init()
{
    //...
}

void thread_proc()
{
    boost::call_once(&amp;init, once);
}</programlisting>
			</para></description>
			
			<parameter name="func">
				<paramtype>void (*func)()</paramtype>
			</parameter>
			
			<parameter name="flag">
				<paramtype>once_flag&amp;</paramtype>
			</parameter>
			
			<requires>The function <code>func</code> shall not throw
			exceptions.</requires>
			
			<effects>As if (in an atomic fashion): 
			<code>if (flag == BOOST_ONCE_INIT) func();</code></effects>
			
			<postconditions><code>flag != BOOST_ONCE_INIT</code>
			</postconditions>
		</function>
	</namespace>
</header>