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:
1.1 KB
|
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/detail/config.hpp> |
---|
8 | |
---|
9 | #include <boost/thread/once.hpp> |
---|
10 | #include <boost/thread/thread.hpp> |
---|
11 | |
---|
12 | #include <boost/test/unit_test.hpp> |
---|
13 | |
---|
14 | #include <libs/thread/test/util.inl> |
---|
15 | |
---|
16 | int once_value = 0; |
---|
17 | boost::once_flag once = BOOST_ONCE_INIT; |
---|
18 | |
---|
19 | void init_once_value() |
---|
20 | { |
---|
21 | once_value++; |
---|
22 | } |
---|
23 | |
---|
24 | void test_once_thread() |
---|
25 | { |
---|
26 | boost::call_once(init_once_value, once); |
---|
27 | } |
---|
28 | |
---|
29 | void do_test_once() |
---|
30 | { |
---|
31 | const int NUMTHREADS=5; |
---|
32 | boost::thread_group threads; |
---|
33 | for (int i=0; i<NUMTHREADS; ++i) |
---|
34 | threads.create_thread(&test_once_thread); |
---|
35 | threads.join_all(); |
---|
36 | BOOST_CHECK_EQUAL(once_value, 1); |
---|
37 | } |
---|
38 | |
---|
39 | void test_once() |
---|
40 | { |
---|
41 | timed_test(&do_test_once, 2); |
---|
42 | } |
---|
43 | |
---|
44 | boost::unit_test_framework::test_suite* init_unit_test_suite(int, char*[]) |
---|
45 | { |
---|
46 | boost::unit_test_framework::test_suite* test = |
---|
47 | BOOST_TEST_SUITE("Boost.Threads: once test suite"); |
---|
48 | |
---|
49 | test->add(BOOST_TEST_CASE(test_once)); |
---|
50 | |
---|
51 | return test; |
---|
52 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.