#include <chrono>
#include <condition_variable>
#include <mutex>
#include <future>
#include <iostream>
using namespace std;
using namespace chrono;
void fun0()
{
steady_clock;
system_clock;
duration<short,ratio<60,1>>;
duration<double,ratio<1,1000>>;
nanoseconds;
microseconds;
milliseconds;
seconds;
minutes;
hours;
milliseconds ms(54802);
seconds s = duration_cast<seconds>(ms);
milliseconds ms2 = s;
milliseconds ms3(1534);
ms3.count();
}
void fun1()
{
int some_task();
future<int> f = async<int()>(some_task);
if(f.wait_for(milliseconds(35)) == future_status::ready)
{
}
}
void fun2()
{
auto start = steady_clock::now();
auto stop = steady_clock::now();
cout << "time = " << duration<double>(stop-start).count();
}
void fun3()
{
condition_variable cond;
bool done;
mutex mut;
const auto t = steady_clock::now()+milliseconds(500);
unique_lock<mutex> lk(mut);
while (!done)
{
if(cond.wait_until(lk,t) == cv_status::timeout)
{
break;
}
}
}
void fun4()
{
}
接受超时的函数:
|