summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/thread/test/test_9079_a.cpp
blob: 3e8ca03fdb1e4973842902f5bda932231ec68cbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (C) 2013 Vicente Botet
//
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

// A

//#include <boost/log/trivial.hpp>
#include <boost/chrono.hpp>
#include <boost/thread.hpp>
#include <boost/thread/condition_variable.hpp>

//#if !defined(BOOST_NO_CXX11_ALIGNAS)
//#error
//#  define BOOST_ALIGNMENT2(x) alignas(x)
//#elif defined(_MSC_VER)
//#error
//#  define BOOST_ALIGNMENT2(x) __declspec(align(x))
//#elif defined(__GNUC__)
//#error
//#  define BOOST_ALIGNMENT(x) __attribute__ ((__aligned__(x)))
//#else
//#error
//#  define BOOST_NO_ALIGNMENT2
//#  define BOOST_ALIGNMENT2(x)
//#endif

typedef boost::chrono::high_resolution_clock Clock;
typedef Clock::time_point TimePoint;

inline TimePoint real_time_now()
{
  return Clock::now();
}

int main()
{
  using namespace boost::chrono;

  boost::condition_variable m_task_spawn_condition;

  boost::mutex main_thread_mutex;
  boost::unique_lock < boost::mutex > main_thread_lock(main_thread_mutex);

  //BOOST_LOG_TRIVIAL(info) << "[TaskScheduler::run_and_wait] Scheduling loop - BEGIN";

  //for (;;)
  {
    static const milliseconds TIME_BACK = milliseconds(1);
    m_task_spawn_condition.wait_until(
        main_thread_lock,
        real_time_now() - TIME_BACK); // wait forever
    m_task_spawn_condition.wait_for( main_thread_lock, - TIME_BACK ); // same problem
    //BOOST_LOG_TRIVIAL(trace) << "TICK";
  }

}