File: myth_create_join_many.c

package info (click to toggle)
massivethreads 1.02-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,924 kB
  • sloc: ansic: 27,814; sh: 4,559; cpp: 3,334; javascript: 1,799; makefile: 1,745; python: 523; asm: 373; perl: 118; lisp: 9
file content (37 lines) | stat: -rw-r--r-- 768 bytes parent folder | download
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

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

#include <myth/myth.h>

typedef struct {
  myth_thread_t id;
  long x;
  long y;
} arg_t;

void * f(void * arg_) {
  arg_t * arg = (arg_t *)arg_;
  long y = arg->x * arg->x;
  return (void *)y;
}

int main(int argc, char ** argv) {
  long nthreads = (argc > 1 ? atol(argv[1]) : 100);
  arg_t * args = (arg_t *)calloc(sizeof(arg_t), nthreads);
  long i;
  for (i = 0; i < nthreads; i++) {
    args[i].x = i + 1;
  }
  int r = myth_create_join_many_ex(&args[0].id, 0, f, args, (void **)&args[0].y,
				   sizeof(arg_t), 0, sizeof(arg_t), sizeof(arg_t),
				   nthreads);
  assert(r == 0);
  for (i = 0; i < nthreads; i++) {
    assert(args[i].y == args[i].x * args[i].x);
  }
  printf("OK\n");
  return 0;
}