CheckForPthreads.c 706 Bytes
Newer Older
1
#include <pthread.h>
2
#include <stdio.h>
3 4 5 6 7
#include <unistd.h>

void* runner(void*);

int res = 0;
8
#ifdef __CLASSIC_C__
9 10
int main()
{
11
  int ac;
12
  char* av[];
13
#else
14 15
int main(int ac, char* av[])
{
16
#endif
17 18 19
  pthread_t tid[2];
  pthread_create(&tid[0], 0, runner, (void*)1);
  pthread_create(&tid[1], 0, runner, (void*)2);
20

21 22
#if defined(__BEOS__) && !defined(__ZETA__) /* (no usleep on BeOS 5.) */
  usleep(1); /* for strange behavior on single-processor sun */
23 24
#endif

25 26
  pthread_join(tid[0], 0);
  pthread_join(tid[1], 0);
27 28 29
  if (ac > 1000) {
    return *av[0];
  }
30 31 32 33 34 35
  return res;
}

void* runner(void* args)
{
  int cc;
36
  for (cc = 0; cc < 10; cc++) {
37
    printf("%p CC: %d\n", args, cc);
38 39
  }
  res++;
40 41
  return 0;
}