thread wrapper

1 #ifndef THREADS_H
2  #define THREADS_H
3
4 #ifdef WIN32
5
6 #include < windows.h >
7 #include < process.h >
8
9 typedef unsigned long PTHREAD;
10
11 static int create_thread(PTHREAD& t, void *(*f) (void *), void* p)
12 {
13 return t = (PTHREAD)_beginthread((void( __cdecl * )( void * ))f, 0, p);
14 }
15
16 #else
17
18 // Use POSIX threading...
19 #include < pthread.h >
20 #include < unistd.h >
21
22 typedef pthread_t PTHREAD;
23
24 static int create_thread(PTHREAD& t, void *(*f) (void *), void* p)
25 {
26 return pthread_create((pthread_t*)&t, 0, f, p);
27 }
28
29 static void Sleep(unsigned long dwMilliseconds)
30 {
31 usleep(dwMilliseconds * 1000);
32 }
33
34 #endif
35
36 #endif // !THREADS_H
37

原文地址:https://www.cnblogs.com/zdxster/p/1871481.html