Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Request timer interrupts in userspace program?

Tags:

c

time

interrupt

Is it possible (preferably in an OS-independent fashion, although I happen to be using Windows) to request a timer interrupt in a userspace program?

Here is some pseudo-code which may illustrate what kind of functionality I'm looking for:

#include <time_library_x.h> //For setHandler() and set_timer_for_ms()

void timerInterruptHandler() {
    update_something();
    set_timer_for_ms(50);
}

void main() {
    setHandler(timerInterruptHandler);
    set_timer_for_ms(50);

    while(1) {
        very_boring_data_collection();
    }
}

Anyone know what "library x" is?

like image 456
Marco Merlini Avatar asked Jun 20 '26 13:06

Marco Merlini


1 Answers

In Windows, there is Timers object to create Timer object and register callback function.

In Linux using SIGALRM and setitimer is common to implement timer things, but I have not seen such libraries which integrates those for mult-platform use.

Windows Timers Example : https://msdn.microsoft.com/en-us/library/windows/desktop/ms644901(v=vs.85).aspx

like image 164
j31d0 Avatar answered Jun 22 '26 03:06

j31d0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!