summaryrefslogtreecommitdiffstats
path: root/test/test_thread.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-08-18 16:57:17 -0400
committerDavid Robillard <d@drobilla.net>2022-08-18 16:57:17 -0400
commit0c001d5c7fd4c6c5d9ceeb55ba5fac1780b441af (patch)
tree7e42a1e6ac699fd7c59ad3dfcd4c7c5be2818c75 /test/test_thread.c
parentb9d58f74ea1d072e7a2d1c862dc7a1e0fe5fccb0 (diff)
downloadzix-0c001d5c7fd4c6c5d9ceeb55ba5fac1780b441af.tar.gz
zix-0c001d5c7fd4c6c5d9ceeb55ba5fac1780b441af.tar.bz2
zix-0c001d5c7fd4c6c5d9ceeb55ba5fac1780b441af.zip
Fix or remove non-portable features in thread API
Thread function return values are inconsistent between nearly every threading API out there. So, just ignore them entirely, and provide a typedef and sentinel value so user code can be portable.
Diffstat (limited to 'test/test_thread.c')
-rw-r--r--test/test_thread.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/test_thread.c b/test/test_thread.c
new file mode 100644
index 0000000..6fe80a5
--- /dev/null
+++ b/test/test_thread.c
@@ -0,0 +1,41 @@
+// Copyright 2012-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#undef NDEBUG
+
+#include "zix/thread.h"
+
+#include <assert.h>
+#include <string.h>
+
+typedef struct {
+ int input;
+ int output;
+} SharedData;
+
+ZIX_THREAD_FUNC
+static ZixThreadResult
+thread_func(void* const arg)
+{
+ SharedData* const data = (SharedData*)arg;
+
+ data->output = data->input * 7;
+
+ return ZIX_THREAD_RESULT;
+}
+
+int
+main(int argc, char** argv)
+{
+ (void)argv;
+
+ ZixThread thread; // NOLINT
+
+ SharedData data = {argc + (int)strlen(argv[0]), 0};
+
+ assert(!zix_thread_create(&thread, 128, thread_func, &data));
+ assert(!zix_thread_join(thread));
+ assert(data.output == data.input * 7);
+
+ return 0;
+}