Back to index

glibc  2.9
Defines | Functions | Variables
tst-once2.c File Reference
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "../test-skeleton.c"

Go to the source code of this file.

Defines

#define N   100
#define TEST_FUNCTION   do_test ()
#define TIMEOUT   4

Functions

static void once_handler (void)
static void * tf (void *arg)
static int do_test (void)

Variables

static pthread_once_t once = PTHREAD_ONCE_INIT
static int global

Define Documentation

#define N   100

Definition at line 26 of file tst-once2.c.

#define TEST_FUNCTION   do_test ()

Definition at line 102 of file tst-once2.c.

#define TIMEOUT   4

Definition at line 103 of file tst-once2.c.


Function Documentation

static int do_test ( void  ) [static]

Definition at line 61 of file tst-once2.c.

{
  pthread_attr_t at;
  pthread_t th[N];
  int cnt;

  if (pthread_attr_init (&at) != 0)
    {
      puts ("attr_init failed");
      return 1;
    }

  if (pthread_attr_setstacksize (&at, 1 * 1024 * 1024) != 0)
    {
      puts ("attr_setstacksize failed");
      return 1;
    }

  for (cnt = 0; cnt < N; ++cnt)
    if (pthread_create (&th[cnt], &at, tf, (void *) (long int) cnt) != 0)
      {
       printf ("creation of thread %d failed\n", cnt);
       return 1;
      }

  if (pthread_attr_destroy (&at) != 0)
    {
      puts ("attr_destroy failed");
      return 1;
    }

  for (cnt = 0; cnt < N; ++cnt)
    if (pthread_join (th[cnt], NULL) != 0)
      {
       printf ("join of thread %d failed\n", cnt);
       return 1;
      }

  return 0;
}

Here is the call graph for this function:

static void once_handler ( void  ) [static]

Definition at line 33 of file tst-once2.c.

{
  struct timespec ts;

  ++global;

  ts.tv_sec = 2;
  ts.tv_nsec = 0;
  nanosleep (&ts, NULL);
}

Here is the caller graph for this function:

static void* tf ( void *  arg) [static]

Definition at line 46 of file tst-once2.c.

{
  pthread_once (&once, once_handler);

  if (global != 1)
    {
      printf ("thread %ld: global == %d\n", (long int) arg, global);
      exit (1);
    }

  return NULL;
}

Here is the call graph for this function:


Variable Documentation

int global [static]

Definition at line 30 of file tst-once2.c.

Definition at line 28 of file tst-once2.c.