diff options
author | Angelos Mouzakitis <a.mouzakitis@virtualopensystems.com> | 2023-10-10 14:33:42 +0000 |
---|---|---|
committer | Angelos Mouzakitis <a.mouzakitis@virtualopensystems.com> | 2023-10-10 14:33:42 +0000 |
commit | af1a266670d040d2f4083ff309d732d648afba2a (patch) | |
tree | 2fc46203448ddcc6f81546d379abfaeb323575e9 /meson/test cases/common/94 threads | |
parent | e02cda008591317b1625707ff8e115a4841aa889 (diff) |
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'meson/test cases/common/94 threads')
-rw-r--r-- | meson/test cases/common/94 threads/meson.build | 16 | ||||
-rw-r--r-- | meson/test cases/common/94 threads/threadprog.c | 40 | ||||
-rw-r--r-- | meson/test cases/common/94 threads/threadprog.cpp | 43 |
3 files changed, 99 insertions, 0 deletions
diff --git a/meson/test cases/common/94 threads/meson.build b/meson/test cases/common/94 threads/meson.build new file mode 100644 index 000000000..1fbb15ac7 --- /dev/null +++ b/meson/test cases/common/94 threads/meson.build @@ -0,0 +1,16 @@ +project('threads', 'cpp', 'c', + default_options : ['cpp_std=c++11']) + +threaddep = dependency('threads') + +test('cppthreadtest', + executable('cppthreadprog', 'threadprog.cpp', + dependencies : threaddep + ) +) + +test('cthreadtest', + executable('cthreadprog', 'threadprog.c', + dependencies : threaddep + ) +) diff --git a/meson/test cases/common/94 threads/threadprog.c b/meson/test cases/common/94 threads/threadprog.c new file mode 100644 index 000000000..7bfb7c444 --- /dev/null +++ b/meson/test cases/common/94 threads/threadprog.c @@ -0,0 +1,40 @@ +#if defined _WIN32 + +#include<windows.h> +#include<stdio.h> + +DWORD WINAPI thread_func(void) { + printf("Printing from a thread.\n"); + return 0; +} + +int main(void) { + DWORD id; + HANDLE th; + printf("Starting thread.\n"); + 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) { + printf("Printing from a thread.\n"); + return NULL; +} + +int main(void) { + 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 diff --git a/meson/test cases/common/94 threads/threadprog.cpp b/meson/test cases/common/94 threads/threadprog.cpp new file mode 100644 index 000000000..3c69dc3a8 --- /dev/null +++ b/meson/test cases/common/94 threads/threadprog.cpp @@ -0,0 +1,43 @@ +/* On Windows not all versions of VS support C++11 and + * some (most?) versions of mingw don't support std::thread, + * even though they do support c++11. Since we only care about + * threads working, do the test with raw win threads. + */ + +#if defined _WIN32 + +#include<windows.h> +#include<stdio.h> + +DWORD WINAPI thread_func(LPVOID) { + printf("Printing from a thread.\n"); + return 0; +} + +int main(void) { + 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<thread> +#include<cstdio> + +void main_func(void) { + printf("Printing from a thread.\n"); +} + +int main(void) { + printf("Starting thread.\n"); + std::thread th(main_func); + th.join(); + printf("Stopped thread.\n"); + return 0; +} + +#endif |