#include "thread/Thread.h" #include "thread/Blocker.h" #include #include static const int COUNT = 3; static const int SLEEP_US = 200*1000; void* run(void* arg); int main() { Thread* thread = NULL; BlockerHandle blocker = createBlocker(); if (blocker == -1) { printf("Main: Failed to create blocker.\n"); return 1; } thread = createThread(&run, &blocker); for (int i = 0; i < COUNT+1; i++) { printf("Main: %d\n", i); usleep(SLEEP_US); } notifyBlocker(blocker); joinThread(thread); freeThread(&thread); freeBlocker(&blocker); return 0; } // --- void* run(void* arg) { BlockerHandle* blocker = arg; for (int i = 0; i < COUNT; i++) { printf("Thread: %d\n", i); usleep(SLEEP_US); } printf("Blocker ID: %d\n", *blocker); lockBlocker(*blocker); printf("Thread: Blocker notified, continuing execution.\n"); return NULL; }