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

« back to all changes in this revision

Viewing changes to deps/boost_intern/src/thread/example/thread_group.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
 
// 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 <iostream>
9
 
#include <boost/detail/lightweight_test.hpp>
10
 
 
11
 
int count = 0;
12
 
boost::mutex mutex;
13
 
 
14
 
void increment_count()
15
 
{
16
 
    boost::unique_lock<boost::mutex> lock(mutex);
17
 
    std::cout << "count = " << ++count << std::endl;
18
 
}
19
 
 
20
 
boost::thread_group threads2;
21
 
boost::thread* th2 = 0;
22
 
 
23
 
void increment_count_2()
24
 
{
25
 
    boost::unique_lock<boost::mutex> lock(mutex);
26
 
    BOOST_TEST(threads2.is_this_thread_in());
27
 
    std::cout << "count = " << ++count << std::endl;
28
 
}
29
 
 
30
 
int main()
31
 
{
32
 
  {
33
 
    boost::thread_group threads;
34
 
    for (int i = 0; i < 3; ++i)
35
 
        threads.create_thread(&increment_count);
36
 
    threads.join_all();
37
 
  }
38
 
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
39
 
  {
40
 
    boost::thread_group threads;
41
 
    for (int i = 0; i < 3; ++i)
42
 
        threads.create_thread(&increment_count);
43
 
    threads.interrupt_all();
44
 
    threads.join_all();
45
 
  }
46
 
#endif
47
 
  {
48
 
    boost::thread_group threads;
49
 
    boost::thread* th = new boost::thread(&increment_count);
50
 
    threads.add_thread(th);
51
 
    BOOST_TEST(! threads.is_this_thread_in());
52
 
    threads.join_all();
53
 
  }
54
 
  {
55
 
    boost::thread_group threads;
56
 
    boost::thread* th = new boost::thread(&increment_count);
57
 
    threads.add_thread(th);
58
 
    BOOST_TEST(threads.is_thread_in(th));
59
 
    threads.remove_thread(th);
60
 
    BOOST_TEST(! threads.is_thread_in(th));
61
 
    th->join();
62
 
  }
63
 
  {
64
 
    {
65
 
      boost::unique_lock<boost::mutex> lock(mutex);
66
 
      boost::thread* th2 = new boost::thread(&increment_count_2);
67
 
      threads2.add_thread(th2);
68
 
    }
69
 
    threads2.join_all();
70
 
  }
71
 
  return boost::report_errors();
72
 
}