| Line | |
|---|
| 1 | // Copyright (C) 2001-2003 |
|---|
| 2 | // William E. Kempf |
|---|
| 3 | // |
|---|
| 4 | // Permission to use, copy, modify, distribute and sell this software |
|---|
| 5 | // and its documentation for any purpose is hereby granted without fee, |
|---|
| 6 | // provided that the above copyright notice appear in all copies and |
|---|
| 7 | // that both that copyright notice and this permission notice appear |
|---|
| 8 | // in supporting documentation. William E. Kempf makes no representations |
|---|
| 9 | // about the suitability of this software for any purpose. |
|---|
| 10 | // It is provided "as is" without express or implied warranty. |
|---|
| 11 | |
|---|
| 12 | #include <boost/thread/thread.hpp> |
|---|
| 13 | #include <boost/thread/once.hpp> |
|---|
| 14 | #include <cassert> |
|---|
| 15 | |
|---|
| 16 | int value=0; |
|---|
| 17 | boost::once_flag once = BOOST_ONCE_INIT; |
|---|
| 18 | |
|---|
| 19 | void init() |
|---|
| 20 | { |
|---|
| 21 | ++value; |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | void thread_proc() |
|---|
| 25 | { |
|---|
| 26 | boost::call_once(&init, once); |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | int main(int argc, char* argv[]) |
|---|
| 30 | { |
|---|
| 31 | boost::thread_group threads; |
|---|
| 32 | for (int i=0; i<5; ++i) |
|---|
| 33 | threads.create_thread(&thread_proc); |
|---|
| 34 | threads.join_all(); |
|---|
| 35 | assert(value == 1); |
|---|
| 36 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.