// #thread_primitives #if OS_WINDOWS struct Condition_Variable { CONDITION_VARIABLE condition_variable; }; struct Semaphore { HANDLE event; }; struct Mutex { CRITICAL_SECTION csection; }; struct OS_Thread { HANDLE windows_thread; s32 windows_thread_id; }; #endif #define POSIX_THREADS OS_LINUX || OS_MACOS || OS_IOS || OS_ANDROID #if OS_MACOS struct Semaphore { task_t owner; semaphore_t event = 0; }; #endif #if OS_LINUX || OS_ANDROID struct Semaphore { sem_t semaphore; }; #endif #if OS_IS_UNIX // #posix threads struct OS_Thread { pthread_t thread_handle; Semaphore is_alive; Semaphore suspended; b32 is_done; }; #endif struct Thread; typedef s64 (*Thread_Proc)(Thread* thread); struct Thread { Thread_Context* context; s64 index; Thread_Proc proc; void* data; OS_Thread os_thread; }; global u32 next_thread_index = 1; // internal Thread thread_start // thread_create -> os_thread_launch // thread_join -> os_thread_join // thread_detach -> os_thread_detach