32 lines
603 B
C++
32 lines
603 B
C++
|
#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 ();
|
||
|
}
|