Back to index

glibc  2.9
Defines | Functions
tst-key1.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 TEST_FUNCTION   do_test ()

Functions

int do_test (void)

Define Documentation

#define TEST_FUNCTION   do_test ()

Definition at line 88 of file tst-key1.c.


Function Documentation

int do_test ( void  )

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

{
  int max;
#ifdef PTHREAD_KEYS_MAX
  max = PTHREAD_KEYS_MAX;
#else
  max = _POSIX_THREAD_KEYS_MAX;
#endif
  pthread_key_t *keys = alloca (max * sizeof (pthread_key_t));

  int i;
  for (i = 0; i < max; ++i)
    if (pthread_key_create (&keys[i], NULL) != 0)
      {
       write (2, "key_create failed\n", 18);
       _exit (1);
      }
    else
      {
       printf ("created key %d\n", i);

       if (pthread_setspecific (keys[i], (const void *) (i + 100l)) != 0)
         {
           write (2, "setspecific failed\n", 19);
           _exit (1);
         }
      }

  for (i = 0; i < max; ++i)
    {
      if (pthread_getspecific (keys[i]) != (void *) (i + 100l))
       {
         write (2, "getspecific failed\n", 19);
         _exit (1);
       }

      if (pthread_key_delete (keys[i]) != 0)
       {
         write (2, "key_delete failed\n", 18);
         _exit (1);
       }
    }

  /* Now it must be once again possible to allocate keys.  */
  if (pthread_key_create (&keys[0], NULL) != 0)
    {
      write (2, "2nd key_create failed\n", 22);
      _exit (1);
    }

  if (pthread_key_delete (keys[0]) != 0)
    {
      write (2, "2nd key_delete failed\n", 22);
      _exit (1);
    }

  return 0;
}

Here is the call graph for this function: