• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 int value=0;
12 boost::once_flag once = BOOST_ONCE_INIT;
13 
init()14 void init()
15 {
16     ++value;
17 }
18 
thread_proc()19 void thread_proc()
20 {
21     boost::call_once(&init, once);
22 }
23 
main(int argc,char * argv[])24 int 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 }
32