多線程中,時間限制相關的函數

 

 

// 線程的時間限制
    thread t103(f, 1, 2);
    this_thread::sleep_for(chrono::milliseconds(3));
    chrono::steady_clock::time_point tp = chrono::steady_clock::now()
        + chrono::milliseconds(4);
    this_thread::sleep_until(tp);

    // 鎖的時間限制
    mutex mu;
    unique_lock<mutex> locker(mu);
    locker.try_lock_for(chrono::milliseconds(3));
    locker.try_lock_until(tp);

    // 條件變量的時間限制
    std::condition_variable cond;
    cond.wait_for(locker, chrono::milliseconds(3));
    cond.wait_until(locker, tp);

    // future時間限制
    std::promise<int> p;
    std::future<int> f = p.get_future();
    f.wait_for(chrono::milliseconds(3));
    f.wait_until(tp);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章