通过 setitimer 使用计时器时使用 Sleep() [英] Using Sleep() while using timers through setitimer

查看:37
本文介绍了通过 setitimer 使用计时器时使用 Sleep()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过 sys/time.h 中的 setitimer 函数在我的 C++ 代码中使用计时器.这将 SIGALRM 信号映射到我的计时器处理程序方法.在此之后,我无法使用睡眠功能.我假设这是因为 sleep 也使用 SIGALRM 信号.您能提出解决此问题的任何解决方法吗?

I am using a timer in my C++ code through setitimer function from sys/time.h. This maps the SIGALRM signal to my timer handler method. After this I am not able to use sleep function. I am assuming it is because sleep uses SIGALRM signal as well. Can you suggest any workaround for this problem?

感谢回复.

推荐答案

您可以尝试使用 select() 就像一个计时器.我不知道它是否使用 SIGALRM 但它应该很容易测试.类似的东西:

You can try using select() just as a timer. I don't know if it uses SIGALRM or not but it should be simple to test. Something like:

   timeval t = {1, 0};

   select(0, NULL, NULL, NULL, &t);

这篇关于通过 setitimer 使用计时器时使用 Sleep()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆