Back to index

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

Go to the source code of this file.

Defines

#define N   2
#define TEST_FUNCTION   do_test ()

Functions

static void * tf1 (void *arg)
static void * tf2 (void *arg)
static int do_test (void)

Variables

const int max = _POSIX_THREAD_KEYS_MAX
static pthread_key_tkeys

Define Documentation

#define N   2
#define TEST_FUNCTION   do_test ()

Definition at line 136 of file tst-key4.c.


Function Documentation

static int do_test ( void  ) [static]

Definition at line 66 of file tst-key4.c.

{
  keys = alloca (max * sizeof (pthread_key_t));

  int i;
  for (i = 0; i < max; ++i)
    if (pthread_key_create (&keys[i], NULL) != 0)
      {
       puts ("key_create failed");
       exit (1);
      }

  pthread_attr_t a;

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

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

  for (i = 0; i < 10; ++i)
    {
      int j;
#define N 2
      pthread_t th[N];
      for (j = 0; j < N; ++j)
       if (pthread_create (&th[j], NULL, tf1, NULL) != 0)
         {
           puts ("1st create failed");
           exit (1);
         }

      for (j = 0; j < N; ++j)
       if (pthread_join (th[j], NULL) != 0)
         {
           puts ("1st join failed");
           exit (1);
         }

      for (j = 0; j < N; ++j)
       if (pthread_create (&th[j], NULL, tf2, NULL) != 0)
         {
           puts ("2nd create failed");
           exit (1);
         }

      for (j = 0; j < N; ++j)
       if (pthread_join (th[j], NULL) != 0)
         {
           puts ("2nd join failed");
           exit (1);
         }
    }

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

  return 0;
}

Here is the call graph for this function:

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

Definition at line 36 of file tst-key4.c.

{
  int i;
  for (i = 0; i < max; ++i)
    if (pthread_setspecific (keys[i], (void *) (long int) (i + 1)) != 0)
      {
       puts ("setspecific failed");
       exit (1);
      }

  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 51 of file tst-key4.c.

{
  int i;
  for (i = 0; i < max; ++i)
    if (pthread_getspecific (keys[i]) != NULL)
      {
       printf ("getspecific for key %d not NULL\n", i);
       exit (1);
      }

  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

pthread_key_t* keys [static]

Definition at line 32 of file tst-key4.c.

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