Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setitimer or poll for system time ? 1

Status
Not open for further replies.

Themuppeteer

Programmer
Apr 4, 2001
449
BE
Hello guys,

I have a program that uses the settimer function.
There is an alarm system behind it,and there has to be able to set a delay between the occurence of the alarm and the actual reporting of it.
Anyway, the delay is most of the time not correct! I did not program the timer stuff (somebody else did), but I have to solve the problems now. Shouldn't it be better to poll for the system time in every loop and copare to that instead of having a system where every second the timer function sets a boolean to true ? I think the guy did it for performance reasons but I'm not sure.
Do you know a explanation why the setitimer does not work fine ?
Does polling for the system time every loop take a lot of the cpu ?


Any hints ? remarks ?


thnx!



Greetz,
img


NOSPAM_themuppeteer@hotmail.com (for mails, remove the NOSPAM_)

"Those who say they understand chess, understand nothing"

-- Robert HUBNER
 
> the delay is most of the time not correct!
By how much?

If its always within a second or so, then I'd probably say that it was working within acceptable limits.

Read the disclaimers for timers.
[tt] Timers will never expire before the requested time, instead expiring
some short, constant time afterwards, dependent on the system timer
resolution (currently 10ms). Upon expiration, a signal will be gener-
ated and the timer reset. If the timer expires while the process is
active (always true for ITIMER_VIRT) the signal will be delivered imme-
diately when generated. Otherwise the delivery will be offset by a
small time dependent on the system loading.
[/tt]

If you're looking for high precision, then interval timers are probably not what you want.

Sure you can poll for time, but that would be at the expense of CPU load on your system.

Bear in mind that your OS is sharing resources between your program and other programs as well.

--
 
It was by a few seconds..but to my great surprise, I've noticed that the code concerning the setitimer function is dead code..its not used for anything. So I can't blame the function. But I work with polling now, and it seems to work great. Also the cpu load doesn't go to high.
Thanks for the reply Salem I will remember the information.


Greetz,
img


NOSPAM_themuppeteer@hotmail.com (for mails, remove the NOSPAM_)

"Those who say they understand chess, understand nothing"

-- Robert HUBNER
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top