File: test_thread.c

package info (click to toggle)
zix 0.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 828 kB
  • sloc: ansic: 9,083; cpp: 479; python: 127; makefile: 6
file content (45 lines) | stat: -rw-r--r-- 760 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2012-2022 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC

#undef NDEBUG

#include <zix/status.h>
#include <zix/thread.h>

#include <assert.h>
#include <string.h>

typedef struct {
  int input;
  int output;
} SharedData;

static ZixThreadResult ZIX_THREAD_FUNC
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};

  ZixStatus st = zix_thread_create(&thread, 128, thread_func, &data);
  assert(!st);

  st = zix_thread_join(thread);
  assert(!st);

  assert(data.output == data.input * 7);

  return 0;
}