Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/thread/test/test_barrier.cpp @ 29

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

updated boost from 1_33_1 to 1_34_1

File size: 1.2 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/thread.hpp>
10#include <boost/thread/barrier.hpp>
11
12#include <boost/test/unit_test.hpp>
13
14namespace {
15
16// Shared variables for generation barrier test
17const int N_THREADS=10;
18boost::barrier gen_barrier(N_THREADS);
19boost::mutex mutex;
20long global_parameter;
21
22void barrier_thread()
23{
24    for (int i = 0; i < 5; ++i)
25    {
26        if (gen_barrier.wait())
27        {
28            boost::mutex::scoped_lock lock(mutex);
29            global_parameter++;
30        }
31    }
32}
33
34} // namespace
35
36void test_barrier()
37{
38    boost::thread_group g;
39    global_parameter = 0;
40
41    for (int i = 0; i < N_THREADS; ++i)
42        g.create_thread(&barrier_thread);
43
44    g.join_all();
45
46    BOOST_CHECK(global_parameter == 5);
47}
48
49boost::unit_test_framework::test_suite* init_unit_test_suite(int, char*[])
50{
51    boost::unit_test_framework::test_suite* test =
52        BOOST_TEST_SUITE("Boost.Threads: barrier test suite");
53
54    test->add(BOOST_TEST_CASE(&test_barrier));
55
56    return test;
57}
Note: See TracBrowser for help on using the repository browser.