本文整理汇总了C++中std::timed_mutex::unlock方法的典型用法代码示例。如果您正苦于以下问题:C++ timed_mutex::unlock方法的具体用法?C++ timed_mutex::unlock怎么用?C++ timed_mutex::unlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::timed_mutex
的用法示例。
在下文中一共展示了timed_mutex::unlock方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
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();
}
}
示例2: f1
void f1()
{
time_point t0 = Clock::now();
assert(m.try_lock_until(Clock::now() + ms(300)) == true);
time_point t1 = Clock::now();
m.unlock();
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
示例3: main
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: fireworks
void fireworks () {
// waiting to get a lock: each thread prints "-" every 200ms:
while (!mtx.try_lock_for(std::chrono::milliseconds(200))) {
std::cout << "-";
}
// got a lock! - wait for 1s, then this thread prints "*"
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
std::cout << "*\n";
mtx.unlock();
}
示例5: tc_libcxx_thread_thread_timedmutex_class_try_lock_until
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;
}
示例6: ms
static int f1()
{
time_point t0 = Clock::now();
TC_ASSERT_EXPR(m.try_lock_until(Clock::now() + ms(300)) == true);
time_point t1 = Clock::now();
m.unlock();
ns d = t1 - t0 - ms(250);
TC_ASSERT_EXPR(d < ms(50)); // within 50ms
return 0;
}
示例7: main
/**
* 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;
}
示例8: thread_function_increase_timemutex
void thread_function_increase_timemutex()
{
for (int i=0; i<5; i++)
{
if(g_counter_time_mutex.try_lock_for(std::chrono::seconds(1)))
//g_counter_mutex.lock();
{
++g_counter;
cout << this_thread::get_id() << ": " << i << endl;
g_counter_time_mutex.unlock();
this_thread::sleep_for(std::chrono::seconds(2));
}
}
}
示例9: work
void work(){
std::chrono::milliseconds timeout(100);
while(true){
if(mutex.try_lock_for(timeout)){
std::cout << std::this_thread::get_id() << ": do work with the mutex" << std::endl;
std::chrono::milliseconds sleepDuration(250);
std::this_thread::sleep_for(sleepDuration);
mutex.unlock();
std::this_thread::sleep_for(sleepDuration);
} else {
std::cout << std::this_thread::get_id() << ": do work without mutex" << std::endl;
std::chrono::milliseconds sleepDuration(100);
std::this_thread::sleep_for(sleepDuration);
}
}
}
示例10: test
void test(const std::string& threadName){
std::chrono::milliseconds timeout(100);
for(int i = 0; i < 10; ++i){
// Give up trying to acquire the lock after a period of time.
if(timeLock.try_lock_for(timeout)){
std::cout << threadName << " - locked mutex." << std::endl;
std::chrono::milliseconds sleepDuration(500);
std::this_thread::sleep_for(sleepDuration);
timeLock.unlock();
} else {
std::cout << threadName << " - failed to lock mutex." << std::endl;
std::chrono::milliseconds sleepDuration(250);
std::this_thread::sleep_for(sleepDuration);
}
}
}
示例11: unlockInitMutex
static void unlockInitMutex(CFRunLoopTimerRef timer, void* info) {
initialized = true;
initMutex.unlock();
stopInitTimer();
}