libtimers is a native library to handle tons of timers.
Note: This is a work in progress.
The following code demonstrates an example which uses libtimers to print tick
every second.
#include <stdio.h>
#include <timers.h>
void callback(void *arg) {
printf("> tick\n");
timers_start(1000 /* ms */, callback, NULL);
}
int main() {
timers_init();
timers_start(1000 /* ms */, callback, NULL);
// ... do other time-consuming stuff
timers_cleanup();
return 0;
}
Now, you can build and run the program.
$ gcc -o ticker ticker.c -ltimers
$ ./ticker
> tick
> tick
> ...
-
Extend to above 1k timersNow supports up to 100k timers -
Reduce memory footprintNow uses chunks to store timers - Support for Windows threads
- Tickers (repeating timers)
libtimers is published under GPL-3.0 license.