Created
June 20, 2025 06:24
-
-
Save jacobsapps/ac84db37d3dfbebbbe7f39631033f5aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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