OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [test/] [pthread/] [ex1.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* Creates two threads, one printing 10000 "a"s, the other printing
2
   10000 "b"s.
3
   Illustrates: thread creation, thread joining. */
4
 
5
#include <stddef.h>
6
#include <stdio.h>
7
#include <unistd.h>
8
#include "pthread.h"
9
 
10
void * process(void * arg)
11
{
12
  int i;
13
  fprintf(stderr, "Starting process %s\n", (char *) arg);
14
  for (i = 0; i < 10000; i++) {
15
    write(1, (char *) arg, 1);
16
  }
17
  return NULL;
18
}
19
 
20
int main(void)
21
{
22
  int retcode;
23
  pthread_t th_a, th_b;
24
  void * retval;
25
 
26
  retcode = pthread_create(&th_a, NULL, process, (void *) "a");
27
  if (retcode != 0) fprintf(stderr, "create a failed %d\n", retcode);
28
  else fprintf(stderr, "create a succeeded %d\n", retcode);
29
  retcode = pthread_create(&th_b, NULL, process, (void *) "b");
30
  if (retcode != 0) fprintf(stderr, "create b failed %d\n", retcode);
31
  else fprintf(stderr, "create b succeeded %d\n", retcode);
32
  retcode = pthread_join(th_a, &retval);
33
  if (retcode != 0) fprintf(stderr, "join a failed %d\n", retcode);
34
  else fprintf(stderr, "join a succeeded %d\n", retcode);
35
  retcode = pthread_join(th_b, &retval);
36
  if (retcode != 0) fprintf(stderr, "join b failed %d\n", retcode);
37
  else fprintf(stderr, "join b succeeded %d\n", retcode);
38
  return 0;
39
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.