This commit is contained in:
2025-02-11 10:16:05 +03:00
parent 163188a814
commit 3a07a9b5ed
7 changed files with 111 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
#ifdef _WIN32
#include <windows.h>
#else
#include <pthread.h>
#include <unistd.h>
#endif
#include <stdio.h>
#include "time.h"
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
+13
View File
@@ -0,0 +1,13 @@
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
void wait(int time) {
#ifdef _WIN32
Sleep(time*1000);
#else
sleep(time);
#endif
}