| 1 |
/* On Windows not all versions of VS support C++11 and |
| 2 |
* some (most?) versions of mingw don't support std::thread, |
| 3 |
* even though they do support c++11. Since we only care about |
| 4 |
* threads working, do the test with raw win threads. |
| 5 |
*/ |
| 6 |
|
| 7 |
#if defined _WIN32 |
| 8 |
|
| 9 |
#include<windows.h> |
| 10 |
#include<stdio.h> |
| 11 |
|
| 12 |
DWORD WINAPI thread_func(LPVOID) { |
| 13 |
printf("Printing from a thread.\n"); |
| 14 |
return 0; |
| 15 |
} |
| 16 |
|
| 17 |
int main(void) { |
| 18 |
printf("Starting thread.\n"); |
| 19 |
HANDLE th; |
| 20 |
DWORD id; |
| 21 |
th = CreateThread(NULL, 0, thread_func, NULL, 0, &id); |
| 22 |
WaitForSingleObject(th, INFINITE); |
| 23 |
printf("Stopped thread.\n"); |
| 24 |
return 0; |
| 25 |
} |
| 26 |
#else |
| 27 |
|
| 28 |
#include<thread> |
| 29 |
#include<cstdio> |
| 30 |
|
| 31 |
void main_func(void) { |
| 32 |
printf("Printing from a thread.\n"); |
| 33 |
} |
| 34 |
|
| 35 |
int main(void) { |
| 36 |
printf("Starting thread.\n"); |
| 37 |
std::thread th(main_func); |
| 38 |
th.join(); |
| 39 |
printf("Stopped thread.\n"); |
| 40 |
return 0; |
| 41 |
} |
| 42 |
|
| 43 |
#endif |