用50%的CPU简单的C程序 [英] Simple C app using 50% cpu

查看:90
本文介绍了用50%的CPU简单的C程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用恒定的50%,一个简单的C程序。我不知道为什么,但我喜欢尽可能最小化。

I have a simple C app that uses constant 50%. I don't know why but I like to minimize it as much as possible.

#include <stdlib.h>
#include <stdio.h>
#include <time.h>

void Wait(int seconds)
{
clock_t endwait;
endwait = clock () + seconds * CLK_TCK ;
while (clock() < endwait) {}
}

void main()
{
printf ("program running.\n");
/* Wait( 4 ); */
printf( "Done Waiting!\n" );
printwow();
/* exit(0); */
}

timer_func (void)
{
Wait( 4 );
printwow();
}

printwow()
{
printf ("Say hello");
timer_func();
}

我想这一定是当然的定时器。但我不知道那是肯定的。

I guess it must be the timer of course. But I don't know that for sure.

感谢。

推荐答案

使用一些内置的休眠功能,在不使用的处理器周期为等待,如睡眠 unistd.h中

Use some built-in sleep function, that does not use processor cycles to "wait", like sleep from unistd.h.

这篇关于用50%的CPU简单的C程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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