Ejemplo n.º 1
0
void f()
{
    typedef std::chrono::system_clock Clock;
    typedef std::chrono::milliseconds milliseconds;
    L1 lk(m0);
    assert(test2 == 0);
    test1 = 1;
    cv.notify_one();
    Clock::time_point t0 = Clock::now();
    while (test2 == 0 &&
           cv.wait_for(lk, milliseconds(250)) == std::cv_status::no_timeout)
        ;
    Clock::time_point t1 = Clock::now();
    if (runs == 0)
    {
        assert(t1 - t0 < milliseconds(250));
        assert(test2 != 0);
    }
    else
    {
        assert(t1 - t0 - milliseconds(250) < milliseconds(5));
        assert(test2 == 0);
    }
    ++runs;
}
Ejemplo n.º 2
0
Archivo: main.cpp Proyecto: CCJY/coliru
void waits(int idx)
{
    std::unique_lock<std::mutex> lk(cv_m);
    if(cv.wait_for(lk, std::chrono::milliseconds(idx*100), [](){return i == 1;})) 
        std::cerr << "Thread " << idx << " finished waiting. i == " << i << '\n';
    else
        std::cerr << "Thread " << idx << " timed out. i == " << i << '\n';
}
Ejemplo n.º 3
0
		void unlock() {
			if ( --counter == 0 ) {
				cv.notify_all();
			} else { 
				std::unique_lock<sync_object_type>    barrier_lock(sync);
				while(counter != 0)
					cv.wait_for(barrier_lock, std::chrono::milliseconds(1));
			}
		}
Ejemplo n.º 4
0
int
main()
{
    std::set_terminate(f1);
    try
    {
        std::thread(signal_me).detach();
        mut.lock();
        cv.wait_for(mut, std::chrono::milliseconds(250));
    }
    catch (...) {}
    assert(false);
}
Ejemplo n.º 5
0
void f()
{
    typedef std::chrono::system_clock Clock;
    typedef std::chrono::milliseconds milliseconds;
    L1 lk(m0);
    assert(test2 == 0);
    test1 = 1;
    cv.notify_one();
    Clock::time_point t0 = Clock::now();
    bool r = cv.wait_for(lk, milliseconds(250), Pred(test2));
    Clock::time_point t1 = Clock::now();
    if (runs == 0)
    {
        assert(t1 - t0 < milliseconds(250));
        assert(test2 != 0);
    }
    else
    {
        assert(t1 - t0 - milliseconds(250) < milliseconds(5));
        assert(test2 == 0);
    }
    ++runs;
}