#ifdef _WIN32#include <windows.h>extern "C" { extern int getopt (int, char * const *, const char *); Extern char *optarg;} #define PATHD ' \ \ ' typedef handle thread_t; #define thread_create (thrp, attr, &NBSP;FUNC,&NBSP;ARG) ((* (THRP) = createthread (null, 0, (Lpthread_start_routine) (func), (ARG), 0, null)) == null) ? -1 : 0) #define thread_join (THR,&NBSP;STATUSP) ((WaitForSingleObject (THR), infinite == wait_object_0) && ( Statusp == null) ? 0 : (GetExitCodeThread (THR), (Lpdword) (STATUSP)) ( ? 0 : -1))) typedef handle mutex_t; #define &NBSP;MUTEX_INIT (m, attr) (((* (m) = createmutex (null, false, null) != null) ? 0 : -1) #define mutex_lock (m) ((WaitForSingleObject (* (m), INFINITE) == wait_object_0) ? 0 : -1) #define mutex_unlock (m) (ReleaseMutex (* (m)) ? 0 : -1) #else #include <pthread.h> #include <unistd.h> #define PATHD '/' typedef pthread_t thread_t; #define thread_ Create (Thrp, attr, func, arg) pthread_create ((THRP), (attr), (func), (ARG)) #define Thread_join (THR,&NBSP;STATUSP) pthread_join ((THR), (STATUSP)) Typedef pthread_mutex_t mutex _t, #define &NBSP;MUTEX_INIT (m, attr) pthread_mutex_init ((m), (attr)) # Define mutex_lock (m) pthread_mutex_lock ( m) #define mutex_unlock (M) pthread_mutex_unlock (M) # endif
Using thread_create-related macro definitions under Windows