Events in C++

Does anyone have an idea how to register for system clock tick events?
What do you mean by that? Are you talking about the PIT (if so, you need kernel-mode access)?
I want to do some function every second say, but it could be at some other interval like every 0.1 seconds, I want to register for system clock events, then I can sit back and watch code being triggered by these events.
What OS?
Ah yes, sorry, Windows 7 64-bit
there are two basic ways to get the events. the first (and usual) way is to create a window procedure to receive the timer events. (you'll have to create a window for this too, but it can be hidden if you like.) Read some Win32 tutorials for more. The second is to use one of the 'wait' functions -- either waiting on a timer control or as the timer itself. For an example of using a wait function as a timer, see here: http://www.cplusplus.com/forum/beginner/5619/#msg25047

Hope this helps.
Can't you use the POSIX alarm() function? I think it only has a resolution of half a second though.
Try this code:

1
2
3
4
5
6
void pause(int dur)
{
int temp = time(NULL) + dur;

while(temp > time(NULL));
}


Just Remember: When you want to pause your program(This is an example ->)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// EXAMPLE
#include <iostream>
#include <ctime>
void pause(int dur);
using namespace std;
int main (void){


cout << "I will pause my program for eight seconds.. ;D" << endl;
pause(8); 
cout << "The program paused for 8 seconds..." << endl;

return 0;
}

void pause(int dur)
{
int temp = time(NULL) + dur;

while(temp > time(NULL));
}

Let me know if this was what you were looking for.
Last edited on
@Code Assassin:
Your pause function would spike the CPU, which isn't gonna fly if other processes are running. If you want to pause for X milliseconds or whatever units, without CPU spikes, you will have to look into platform-specific functions (i.e. Sleep() in Windows).
Aw.

I thought I had the solution :(
Topic archived. No new replies allowed.