up
This commit is contained in:
@@ -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
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user