当前位置: 首页>>代码示例>>C++>>正文


C++ timed_mutex::unlock方法代码示例

本文整理汇总了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();
    }
}
开发者ID:32bitmicro,项目名称:riscv-libcxx,代码行数:17,代码来源:try_lock_until.pass.cpp

示例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
}
开发者ID:32bitmicro,项目名称:riscv-libcxx,代码行数:9,代码来源:try_lock_until.pass.cpp

示例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;
}
开发者ID:ingowald,项目名称:llvm-project,代码行数:19,代码来源:mutex_duration.pass.cpp

示例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();
}
开发者ID:DanBrennan33,项目名称:SenecaOOP345-attic,代码行数:10,代码来源:mutex-try_lock_for.cpp

示例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;
}
开发者ID:drashti304,项目名称:TizenRT,代码行数:19,代码来源:try_lock_until.pass.cpp

示例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;
}
开发者ID:drashti304,项目名称:TizenRT,代码行数:10,代码来源:try_lock_until.pass.cpp

示例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;
}
开发者ID:jainvishal,项目名称:blog,代码行数:17,代码来源:gcc4_8_mutex_timing_issue.cpp

示例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));
        }
    }
}
开发者ID:guyueguakenan,项目名称:StudyProjects,代码行数:14,代码来源:Mutex.cpp

示例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);
        }
    }
}
开发者ID:yin8086,项目名称:cpp11,代码行数:21,代码来源:timedmutex.cpp

示例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);
        }
    }
}
开发者ID:DForshner,项目名称:CPPExperiments,代码行数:21,代码来源:RecursiveMutex.cpp

示例11: unlockInitMutex

static void unlockInitMutex(CFRunLoopTimerRef timer, void* info) {
	initialized = true;
	initMutex.unlock();
	stopInitTimer();
}
开发者ID:ingo,项目名称:titanium_mobile,代码行数:5,代码来源:runloop.cpp

示例12: unlock

		void unlock()
		{ _m.unlock(); }
开发者ID:koplyarov,项目名称:stalemate,代码行数:2,代码来源:mutex.hpp


注:本文中的std::timed_mutex::unlock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。