forked from mesonbuild/meson
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
project('threads', 'cpp') | ||
project('threads', 'cpp', 'c') | ||
|
||
test('threadtest', | ||
executable('threadprog', 'threadprog.cpp', | ||
dependencies : dependency('threads') | ||
threaddep = dependency('threads') | ||
|
||
test('cppthreadtest', | ||
executable('cppthreadprog', 'threadprog.cpp', | ||
dependencies : threaddep | ||
) | ||
) | ||
|
||
test('cthreadtest', | ||
executable('cthreadprog', 'threadprog.c', | ||
dependencies : threaddep | ||
) | ||
) |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#if defined _WIN32 | ||
|
||
#include<windows.h> | ||
#include<stdio.h> | ||
|
||
DWORD WINAPI thread_func(LPVOID ignored) { | ||
printf("Printing from a thread.\n"); | ||
return 0; | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
printf("Starting thread.\n"); | ||
HANDLE th; | ||
DWORD id; | ||
th = CreateThread(NULL, 0, thread_func, NULL, 0, &id); | ||
WaitForSingleObject(th, INFINITE); | ||
printf("Stopped thread.\n"); | ||
return 0; | ||
} | ||
#else | ||
|
||
#include<pthread.h> | ||
#include<stdio.h> | ||
|
||
void* main_func(void* ignored) { | ||
printf("Printing from a thread.\n"); | ||
return NULL; | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
pthread_t thread; | ||
int rc; | ||
printf("Starting thread.\n"); | ||
rc = pthread_create(&thread, NULL, main_func, NULL); | ||
rc = pthread_join(thread, NULL); | ||
printf("Stopped thread.\n"); | ||
return rc; | ||
} | ||
|
||
#endif |