Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/thread/example/once.cpp @ 33

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

updated boost from 1_33_1 to 1_34_1

File size: 630 bytes
Line 
1// Copyright (C) 2001-2003
2// William E. Kempf
3//
4//  Distributed under the Boost Software License, Version 1.0. (See accompanying
5//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7#include <boost/thread/thread.hpp>
8#include <boost/thread/once.hpp>
9#include <cassert>
10
11int value=0;
12boost::once_flag once = BOOST_ONCE_INIT;
13
14void init()
15{
16    ++value;
17}
18
19void thread_proc()
20{
21    boost::call_once(&init, once);
22}
23
24int main(int argc, char* argv[])
25{
26    boost::thread_group threads;
27    for (int i=0; i<5; ++i)
28        threads.create_thread(&thread_proc);
29    threads.join_all();
30    assert(value == 1);
31}
Note: See TracBrowser for help on using the repository browser.