File: myth_create_1.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 (32 lines) | stat: -rw-r--r-- 591 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
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

#include <myth/myth.h>

void * f(void * x) {
  long i = (long)x;
  return (void *)(i * i);
}

myth_thread_t parent_th;
myth_thread_t th[1000];
void * ret[1000];

//#define nthreads 100
int main(int argc, char ** argv) {
  int nthreads = (argc > 1 ? atoi(argv[1]) : 100);
  long i;
  parent_th = myth_self();
  for (i = 0; i < nthreads; i++) {
    th[i] = myth_create(f, (void *)i);
    myth_join(th[i], &ret[i]);
    if (ret[i] != (void *)(i * i)) {
      printf("NG\n");
      return 1;
    }
  }
  printf("OK\n");
  return 0;
}