简体   繁体   English

我如何使用C ++和Boost创建看门狗计时器

[英]How can i create watchdog timer using c++ and boost

What is the best and shortest way to create a WatchDogTimer class, which can wait some time and then died? 创建WatchDogTimer类的最佳和最短方法是什么,它可以等待一段时间然后死掉?

So when I'm doing something like 所以当我做类似的事情时

WatchDogTimer wdt (10);

wdt will be available only in next 10 seconds. wdt仅在接下来的10秒内可用。

How can I do this? 我怎样才能做到这一点?

ps: yeah, I saw that thread, but it did not actually help. ps:是的,我看到了那个线程,但实际上并没有帮助。

Create an object on the heap with new and hand it to a shared_ptr . 使用new在堆上创建一个对象,并将其传递给shared_ptr Then hold that shared pointer only from a thread that sleeps for 10 seconds before exiting. 然后仅在退出前休眠10秒的线程中持有该共享指针。 Make sure the thread is the only instance of shared_ptr and all other references are weak_ptr s. 确保该线程是shared_ptr的唯一实例,而所有其他引用均为weak_ptr After the 10 seconds weak_ptr::get() will return null. 10秒钟后, weak_ptr::get()将返回null。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM