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

« back to all changes in this revision

Viewing changes to deps/boost_intern/src/thread/test/sync/conditions/condition_variable/dtor_pass.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
 
//===----------------------------------------------------------------------===//
2
 
//
3
 
//                     The LLVM Compiler Infrastructure
4
 
//
5
 
// This file is dual licensed under the MIT and the University of Illinois Open
6
 
// Source Licenses. See LICENSE.TXT for details.
7
 
//
8
 
//===----------------------------------------------------------------------===//
9
 
// Copyright (C) 2011 Vicente J. Botet Escriba
10
 
//
11
 
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
12
 
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
13
 
 
14
 
// <boost/thread/condition_variable>
15
 
 
16
 
// class condition_variable;
17
 
 
18
 
// condition_variable(const condition_variable&) = delete;
19
 
 
20
 
#include <boost/thread/condition_variable.hpp>
21
 
#include <boost/thread/mutex.hpp>
22
 
#include <boost/thread/thread.hpp>
23
 
#include <boost/thread/locks.hpp>
24
 
#include <boost/detail/lightweight_test.hpp>
25
 
 
26
 
boost::condition_variable* cv;
27
 
boost::mutex m;
28
 
typedef boost::unique_lock<boost::mutex> Lock;
29
 
 
30
 
bool f_ready = false;
31
 
bool g_ready = false;
32
 
 
33
 
void f()
34
 
{
35
 
  Lock lk(m);
36
 
  f_ready = true;
37
 
  cv->notify_one();
38
 
  cv->wait(lk);
39
 
  delete cv;
40
 
}
41
 
 
42
 
void g()
43
 
{
44
 
  Lock lk(m);
45
 
  g_ready = true;
46
 
  cv->notify_one();
47
 
  while (!f_ready)
48
 
  {
49
 
    cv->wait(lk);
50
 
  }
51
 
  cv->notify_one();
52
 
}
53
 
 
54
 
int main()
55
 
{
56
 
  cv = new boost::condition_variable;
57
 
  boost::thread th2(g);
58
 
  Lock lk(m);
59
 
  while (!g_ready)
60
 
  {
61
 
    cv->wait(lk);
62
 
  }
63
 
  lk.unlock();
64
 
  boost::thread th1(f);
65
 
  th1.join();
66
 
  th2.join();
67
 
  return boost::report_errors();
68
 
}
69