I would like to know if a program / a thread was dispatched / scheduled in C under Linux and if possible how often. The reason is that I'm measuring the runtime of a loop and want to prevent false results.
This is a minimal example:
#include <stdio.h>
int times_dispatched() {
// how to check?
return 0;
}
int main() {
int i, dummy = 0;
for(i=0; i<10000000; i++) {
dummy++;
}
printf("counted to %d; program was dispatched %d times\n", dummy, times_dispatched());
}