Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jacobsapps/ac84db37d3dfbebbbe7f39631033f5aa to your computer and use it in GitHub Desktop.
Save jacobsapps/ac84db37d3dfbebbbe7f39631033f5aa to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
// we're aliasing here since modern MacOS doesn't use the same system toolbox
void SystemTask() { usleep(50000); } // Yield to system
int WaitNextEvent() { SystemTask(); return rand() % 2; } // 50% chance of event
void doStuff() { printf("Doing stuff!\n"); }
int main() {
srand(time(NULL));
int done = 0;
while (!done) {
if (WaitNextEvent()) {
printf("Event received!\n");
doStuff();
done = 1;
} else {
printf("No event recieved, yielding...\n");
}
SystemTask(); // yield to the system after every event loop
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment