延迟 [英] delay

查看:89
本文介绍了延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的多线程应用程序(windows)中,我有几个无限的

循环(虽然它不好......但是我需要它们)。因此他们吃掉了近98%的CPU时间(在任务管理器中显示)。


我决定在程序中延迟200毫秒。但不幸的是我的编译器(Borland 5.5)没有提供任何这样的

功能。


在我的研究中,我发现许多(跛脚)的人通过在延迟区块中添加

不必要的指令来延迟...就像这样


无效延迟()

{

int i = 0,j = 10;

for(i = 0; i< 12345678; i ++)

j * = j;

}


但它不会做我的工作。但我发现通过做一些

信号处理,我可以创建我的延迟功能。


这些功能在Windows中是否可用??? ?

如何实施?????

In my multi threaded application(windows), I have several infinite
loop(though it''s not good to have...but I need them). Hence they eat
nearly 98% of CPU time(it shows in task manager).

I have decided to put a delay of 200 ms in the program. But
unfortunately my Compiler(Borland 5.5) is not providing any such
functionalities.

In my research, I found that many (lame) people put delay by putting
unnecessary instructions in the delay block....like this

void delay()
{
int i=0,j=10;
for(i=0;i<12345678;i++)
j *=j;
}

But it won''t do my job. But I have found that by doing some kind of
signal handling, I can create my delay function.

Does such functionality is available in windows ????
How can I implement it ????

推荐答案

2008年10月7日7: 13,asit写道:
On 7 Oct 2008 at 7:13, asit wrote:

在我的多线程应用程序(windows)中,我有几个无限的

循环(尽管它不是很高兴...但我需要他们)。因此他们吃掉了近98%的CPU时间(在任务管理器中显示)。


我决定在程序中延迟200毫秒。但不幸的是我的编译器(Borland 5.5)没有提供任何这样的

功能。


但它不会做我的工作。但我发现通过做一些

信号处理,我可以创建我的延迟功能。


这些功能在Windows中是否可用??? ?

如何实施????
In my multi threaded application(windows), I have several infinite
loop(though it''s not good to have...but I need them). Hence they eat
nearly 98% of CPU time(it shows in task manager).

I have decided to put a delay of 200 ms in the program. But
unfortunately my Compiler(Borland 5.5) is not providing any such
functionalities.

But it won''t do my job. But I have found that by doing some kind of
signal handling, I can create my delay function.

Does such functionality is available in windows ????
How can I implement it ????



在POSIX系统上,您正在寻找的函数称为sleep(3),

可以使用SIGALRM信号实现。


Google搜索

" Windows API"睡觉

显示相应的Windows函数被称为Sleep,带有一个

大写的S,并且需要一个long int参数来指定时间长度

等待毫秒。

On POSIX systems, the function you''re looking for is called sleep(3) and
can be implemented using the SIGALRM signal.

Doing a Google search for
"Windows API" sleep
shows that the corresponding Windows function is called Sleep with a
capital S, and takes a long int argument specifying the length of time
to wait in milliseconds.


Antoninus Twink写道:
Antoninus Twink wrote:

2008年10月7日7点:13,asit写道:
On 7 Oct 2008 at 7:13, asit wrote:

>在我的多线程应用程序(windows)中,我有几个无限的循环(尽管它不好)有...但我需要他们)。因此,他们占用了近98%的CPU时间(在任务管理器中显示)。

我决定在程序中延迟200毫秒。但不幸的是我的编译器(Borland 5.5)没有提供任何这样的功能。

但它不能完成我的工作。但我发现通过做某种信号处理,我可以创建我的延迟功能。

Windows中是否有这样的功能????
我该怎么办?实现它????
>In my multi threaded application(windows), I have several infinite
loop(though it''s not good to have...but I need them). Hence they eat
nearly 98% of CPU time(it shows in task manager).

I have decided to put a delay of 200 ms in the program. But
unfortunately my Compiler(Borland 5.5) is not providing any such
functionalities.

But it won''t do my job. But I have found that by doing some kind of
signal handling, I can create my delay function.

Does such functionality is available in windows ????
How can I implement it ????



在POSIX系统上,您正在寻找的函数称为sleep(3),

可以使用SIGALRM信号实现。


On POSIX systems, the function you''re looking for is called sleep(3) and
can be implemented using the SIGALRM signal.



完全无稽之谈。 sleep(3)暂停执行几秒钟。

正确的POSIX函数是nanosleep()。 SIGALRM总共

红鲱鱼。


-

Ian Collins。

Utter nonsense. sleep(3) suspendeds execution for a number of seconds.
The correct POSIX function would be nanosleep(). SIGALRM is a total
red herring.

--
Ian Collins.


2008年10月7日7:48,Ian Collins写道:
On 7 Oct 2008 at 7:48, Ian Collins wrote:

Antoninus Twink写道:
Antoninus Twink wrote:

>在POSIX系统上,您正在寻找的函数称为sleep(3)
,可以使用SIGALRM信号实现。
>On POSIX systems, the function you''re looking for is called sleep(3)
and can be implemented using the SIGALRM signal.



完全没废话。 sleep(3)暂停执行一些

秒。正确的POSIX函数是nanosleep()。

Utter nonsense. sleep(3) suspendeds execution for a number of
seconds. The correct POSIX function would be nanosleep().



像往常一样,你故意误解。


OP的问题是关于Windows的,唯一的一点是提到

POSIX是找到延迟(即睡眠)的正确同义词,

会导致Google搜索成功。


尝试谷歌搜索

Windows API nanosleep

,看看结果有多大。

As usual, you deliberately misunderstand.

The OP''s question was about Windows, and the only point of mentioning
POSIX was to find the correct synonymn for delay (namely sleep) that
results in a successful Google search.

Try googling
"Windows API" nanosleep
and see how useful the results are.


SIGALRM是一个完整的红鲱鱼。
SIGALRM is a total red herring.



OP询问是否可以使用信号实现延迟功能。

原则上,答案显然是肯定的,如警报所示( 2)。

它的参数是以秒为单位的时间这一事实并没有改变它通过向调用进程提供SIGALRM而工作的事实。

。 />

The OP asked whether delay functions can be implemented using signals.
In principle, the answer is clearly yes, as demonstrated by alarm(2).
The fact that its argument is a time in seconds doesn''t change the fact
that it works by delivering a SIGALRM to the calling process.


这篇关于延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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