简体   繁体   中英

Request timer interrupts in userspace program?

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM