~ubuntu-branches/ubuntu/wily/davix/wily

« back to all changes in this revision

Viewing changes to deps/boost_intern/src/thread/test/test_barrier_void_fct.cpp

  • Committer: Package Import Robot
  • Author(s): Mattias Ellert
  • Date: 2015-07-31 13:17:55 UTC
  • mfrom: (5.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20150731131755-mizprbmn7ogv33te
Tags: 0.4.1-1
* Update to version 0.4.1
* Implement Multi-Arch support

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// (C) Copyright 2013 Vicente J. Botet Escriba
2
 
//
3
 
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
4
 
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
 
 
6
 
#define BOOST_THREAD_PROVIDES_INTERRUPTIONS
7
 
 
8
 
#include <boost/thread/detail/config.hpp>
9
 
 
10
 
#include <boost/thread/thread.hpp>
11
 
#include <boost/thread/barrier.hpp>
12
 
 
13
 
#include <boost/detail/lightweight_test.hpp>
14
 
#include <vector>
15
 
 
16
 
namespace {
17
 
 
18
 
 
19
 
// Shared variables for generation barrier test
20
 
long global_parameter;
21
 
 
22
 
void void_fct() {
23
 
  global_parameter++;
24
 
}
25
 
 
26
 
const int N_THREADS=3;
27
 
boost::barrier gen_barrier(N_THREADS, void_fct);
28
 
 
29
 
void barrier_thread()
30
 
{
31
 
    for (int i = 0; i < 5; ++i)
32
 
    {
33
 
        gen_barrier.count_down_and_wait();
34
 
    }
35
 
}
36
 
 
37
 
} // namespace
38
 
 
39
 
void test_barrier()
40
 
{
41
 
    boost::thread_group g;
42
 
    global_parameter = 0;
43
 
 
44
 
    try
45
 
    {
46
 
        for (int i = 0; i < N_THREADS; ++i)
47
 
            g.create_thread(&barrier_thread);
48
 
        g.join_all();
49
 
    }
50
 
    catch(...)
51
 
    {
52
 
        g.interrupt_all();
53
 
        g.join_all();
54
 
        throw;
55
 
    }
56
 
 
57
 
    BOOST_TEST(global_parameter==5);
58
 
 
59
 
}
60
 
 
61
 
int main()
62
 
{
63
 
 
64
 
    test_barrier();
65
 
    return boost::report_errors();
66
 
}
67