#ifdef _WIN32 #include #else #include #include #endif #include void start_thread(void** thread_handle, void* (*task)(void*)) { #ifdef _WIN32 HANDLE thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)task, NULL, 0, NULL); if (thread == NULL) { fprintf(stderr, "Failed to create thread\n"); } *thread_handle = thread; #else pthread_t thread; if (pthread_create(&thread, NULL, task, NULL) != 0) { fprintf(stderr, "Failed to create thread\n"); } pthread_detach(thread); *thread_handle = (void*)thread; #endif } #ifdef _WIN32 void kill_thread(void* thread_handle) { HANDLE thread = (HANDLE)thread_handle; TerminateThread(thread, 0); } #else void kill_thread(void* thread_handle) { pthread_t thread = (pthread_t)thread_handle; pthread_cancel(thread); } #endif