summaryrefslogtreecommitdiffstats
path: root/test cases/common/94 threads
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-29 04:41:38 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-29 04:41:38 +0000
commit7b6e527f440cd7e6f8be2b07cee320ee6ca18786 (patch)
tree4a2738d69fa2814659fdadddf5826282e73d81f4 /test cases/common/94 threads
parentInitial commit. (diff)
downloadmeson-7b6e527f440cd7e6f8be2b07cee320ee6ca18786.tar.xz
meson-7b6e527f440cd7e6f8be2b07cee320ee6ca18786.zip
Adding upstream version 1.0.1.upstream/1.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test cases/common/94 threads')
-rw-r--r--test cases/common/94 threads/meson.build21
-rw-r--r--test cases/common/94 threads/threadprog.c46
-rw-r--r--test cases/common/94 threads/threadprog.cpp43
3 files changed, 110 insertions, 0 deletions
diff --git a/test cases/common/94 threads/meson.build b/test cases/common/94 threads/meson.build
new file mode 100644
index 0000000..6a939ff
--- /dev/null
+++ b/test cases/common/94 threads/meson.build
@@ -0,0 +1,21 @@
+project('threads', 'cpp', 'c',
+ default_options : ['cpp_std=c++11'])
+
+cc = meson.get_compiler('c')
+if cc.has_function_attribute('unused')
+ add_project_arguments('-DHAVE_UNUSED', language: 'c')
+endif
+
+threaddep = dependency('threads')
+
+test('cppthreadtest',
+ executable('cppthreadprog', 'threadprog.cpp',
+ dependencies : threaddep
+ )
+)
+
+test('cthreadtest',
+ executable('cthreadprog', 'threadprog.c',
+ dependencies : threaddep
+ )
+)
diff --git a/test cases/common/94 threads/threadprog.c b/test cases/common/94 threads/threadprog.c
new file mode 100644
index 0000000..19130d5
--- /dev/null
+++ b/test cases/common/94 threads/threadprog.c
@@ -0,0 +1,46 @@
+#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>
+
+#ifdef HAVE_UNUSED
+ #define UNUSED_ATTR __attribute__((unused))
+#else
+ #define UNUSED_ATTR
+#endif
+
+void* main_func(void UNUSED_ATTR *arg) {
+ 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/test cases/common/94 threads/threadprog.cpp b/test cases/common/94 threads/threadprog.cpp
new file mode 100644
index 0000000..3c69dc3
--- /dev/null
+++ b/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