예제 #1
1
		void lock()
		{
			using namespace std::chrono;

			if (_m.try_lock())
				return;

			detail::threading_primitive_guard g;

			if (g.should_detect_deadlocks())
			{
				auto d = milliseconds(TimeoutMs_);
				detail::timer t;
				while (!_m.try_lock_for(d))
					LoggerPolicy_::show_message(detail::make_log_message("Could not lock mutex", get_id(), t.elapsed()));
			}
			else
				_m.lock();
		}
int main()
{
    {
        m.lock();
        std::thread t(f1);
        std::this_thread::sleep_for(ms(250));
        m.unlock();
        t.join();
    }
    {
        m.lock();
        std::thread t(f2);
        std::this_thread::sleep_for(ms(300));
        m.unlock();
        t.join();
    }
}
예제 #3
0
int main(int, char**)
{
    {
        m.lock();
        std::thread t(f1);
        std::this_thread::sleep_for(ms(250));
        m.unlock();
        t.join();
    }
    {
        m.lock();
        std::thread t(f2);
        std::this_thread::sleep_for(ms(300));
        m.unlock();
        t.join();
    }

  return 0;
}
예제 #4
0
int tc_libcxx_thread_thread_timedmutex_class_try_lock_until(void)
{
    {
        m.lock();
        std::thread t(f1);
        std::this_thread::sleep_for(ms(250));
        m.unlock();
        t.join();
    }
    {
        m.lock();
        std::thread t(f2);
        std::this_thread::sleep_for(ms(300));
        m.unlock();
        t.join();
    }
    TC_SUCCESS_RESULT();
    return 0;
}
예제 #5
0
/**
 * main thread that locks the mutex, starts thread then unlocks the mutex after
 * 2 seconds. That allows child thread to lock the mutex.
 * */
int main()
{
	mutex.lock();
	LOG(" M mutex locked");

	std::thread t(f);
	sleep(2);
	mutex.unlock();
	LOG(" M mutex unlocked");
	sleep(2);
	t.join();
	return 0;
}