Created
November 22, 2015 20:26
-
-
Save neuro-sys/fd1540c781a0a07b8973 to your computer and use it in GitHub Desktop.
Revisions
-
neuro-sys created this gist
Nov 22, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ #include "thread.h" #include <stdio.h> #ifdef __WIN32__ #include <windows.h> #else #include <pthread.h> #include <stdlib.h> #endif // __WIN32__ int thread_create(thread_t * thread, void *(*start_routine)(void *), void *arg) { #ifdef __WIN32__ void * addr = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) start_routine, arg, 0, NULL); *thread = addr; return 0; #else *thread = malloc(sizeof (pthread_t)); return pthread_create(*thread, NULL, start_routine, arg); #endif // __WIN32__ } int thread_kill(thread_t * thread) { #ifdef __WIN32__ return TerminateThread(*thread, 9); #else pthread_kill(*((pthread_t *) *thread), 9); free(*thread); return 0; #endif // __WIN32__ } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ #ifndef __THREAD_H_ #define __THREAD_H_ typedef void * thread_t ; int thread_create(thread_t * thread, void *(*start_routine)(void *), void *arg); int thread_kill(thread_t * thread); #endif // __THREAD_H_