当sleep()无法通过警报正常工作时,我还能做什么“睡眠"? [英] What else can i do 'sleep' when the sleep() can't work well with alarm?

查看:110
本文介绍了当sleep()无法通过警报正常工作时,我还能做什么“睡眠"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有许多文件说您应该避免使用带警报的睡眠,因为许多系统将警报用于睡眠实现".实际上,我正遭受着这个问题的困扰. 那么,有谁能帮助我,当sleep()无法通过警报正常工作时,我还能做些睡眠"吗?我已经尝试了Time :: HiRes模块的"usleep",并选择了select()函数.但是他们也不起作用.

There are many documents say "you should avoid using sleep with alarm, since many systems use alarm for the sleep implementation". And actually, I'm suffering with this problem. So does anyone can help me that what else i can do 'sleep' when the sleep() can't work well with alarm? I have already tried 'usleep' of the Time::HiRes module, and select() function. But they didn't work either.

推荐答案

您可以尝试 AnyEvent :

You can try AnyEvent:

use AnyEvent;

my $cv = AnyEvent->condvar;
my $wait_one_and_a_half_seconds = AnyEvent->timer(
    after => 1.5,
    cb => sub { $cv->send }
);     
# now wait till our time has come
$cv->recv;

这篇关于当sleep()无法通过警报正常工作时,我还能做什么“睡眠"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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