introducing-cmake/exercises/src/a.cc

32 lines
603 B
C++
Raw Normal View History

2019-07-27 18:28:47 +02:00
#include <cmake-exercise/a.hh>
#include <chrono>
#include <cstdlib>
#include <iostream>
#include <sstream>
A::A ()
: _t ([] ()
{
{
std::ostringstream oss;
oss << "Starting thread " << std::this_thread::get_id () << std::endl;
std::cout << oss.str() << std::flush;
}
std::this_thread::sleep_for (std::chrono::milliseconds(std::rand() % 100 * 10));
{
std::ostringstream oss;
oss << "Thread " << std::this_thread::get_id () << " finished" << std::endl;
std::cout << oss.str() << std::flush;
}
})
{
}
A::~A ()
{
_t.join ();
}