Skip to content

Instantly share code, notes, and snippets.

@dereckson

dereckson/Makefile

Last active Aug 29, 2015
Embed
What would you like to do?
Use of usleep to idle a thread and avoid full CPU core use.
#include <stdio.h>
#ifdef IDLE
#include <unistd.h>
#endif
int main () {
int a = 0, b = 0, sum = 0;
while (1) {
sum = a + b;
#ifdef IDLE
usleep(1000);
#endif
}
}
all: idle-on idle-off
idle-on:
${CC} -DIDLE idle_test.c -o idle-on
idle-off:
${CC} idle_test.c -o idle-off
clean:
rm -f *.o idle-on idle-off
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment