954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to trigger events at specific times?

Hi
I have to make a C program which has to perform a specified event at a specified time. Something like this...

Print Hello at 13:15
Print Bye at 14:20
Print working at 13:57

Assume that these instructions are already available. I am thinking of creating a doubly linked list which will hold the hour, minute & the text. Then, I will sort them, keeping the earliest event at the start of the list. The problem now is how to make sure that the required event occurs at the very moment that it is supposed to occur. I am thinking that I might require a sort of program that would periodically check the current time(hour, then minute) with that stored in the list. But how should I do this? Also, is there a more efficient way of performing this sort of check?

champnim
Light Poster
31 posts since May 2008
Reputation Points: 16
Solved Threads: 0
 

There are plenty of C features considering time. Read up on them.

The linked list approach seems efficient enough for this task.

Clockowl
Posting Whiz
376 posts since May 2008
Reputation Points: 69
Solved Threads: 28
 

Work out the time between "now" and the time at the head of the list.
Sleep for that amount?

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

i would this in DOS using TSR program to fire events with....
but now..i don't know if it works....

lighthead
Junior Poster in Training
64 posts since Jan 2008
Reputation Points: 72
Solved Threads: 15
 

I think sleep would be a good option...but is it the only one? Also what happens if I initiate a sleep & after that I get a command from the user saying that a certain instruction has to performed before the previous 1st instruction. Is it then possible to update the sleep time accordingly?

champnim
Light Poster
31 posts since May 2008
Reputation Points: 16
Solved Threads: 0
 

>i would this in DOS using TSR program to fire events with....
I would too...15 years ago, and only on DOS because TSRs were a hack to get around the weaknesses of an OS that couldn't handle more than one running program at a time. Now I'd use the event management or polling mechanisms of whatever multitasking OS the program is written for.

>Is it then possible to update the sleep time accordingly?
Yes, but then you're entering the realm of multiple threads/processes. One thread polls for changes to the requirements and another performs work based on the currently saved requirements.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You