Back to index

glibc  2.9
Defines | Functions
tst-tsd1.c File Reference
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include "../test-skeleton.c"

Go to the source code of this file.

Defines

#define TEST_FUNCTION   do_test ()

Functions

static int do_test (void)

Define Documentation

#define TEST_FUNCTION   do_test ()

Definition at line 117 of file tst-tsd1.c.


Function Documentation

static int do_test ( void  ) [static]

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

{
  pthread_key_t key1;
  pthread_key_t key2;
  void *value;
  int result = 0;
  int err;

  err = pthread_key_create (&key1, NULL);
  if (err != 0)
    {
      printf ("1st key_create failed: %s\n", strerror (err));
      return 1;
    }

  /* Initial value must be NULL.  */
  value = pthread_getspecific (key1);
  if (value != NULL)
    {
      puts ("1st getspecific != NULL");
      result = 1;
    }

  err = pthread_setspecific (key1, (void *) -2l);
  if (err != 0)
    {
      printf ("1st setspecific failed: %s\n", strerror (err));
      return 1;
    }

  value = pthread_getspecific (key1);
  if (value == NULL)
    {
      puts ("2nd getspecific == NULL\n");
      result = 1;
    }
  else if (value != (void *) -2l)
    {
      puts ("2nd getspecific != -2l\n");
      result = 1;
    }

  err = pthread_setspecific (key1, (void *) -3l);
  if (err != 0)
    {
      printf ("2nd setspecific failed: %s\n", strerror (err));
      return 1;
    }

  value = pthread_getspecific (key1);
  if (value == NULL)
    {
      puts ("3rd getspecific == NULL\n");
      result = 1;
    }
  else if (value != (void *) -3l)
    {
      puts ("3rd getspecific != -2l\n");
      result = 1;
    }

  err = pthread_key_delete (key1);
  if (err != 0)
    {
      printf ("key_delete failed: %s\n", strerror (err));
      result = 1;
    }


  err = pthread_key_create (&key2, NULL);
  if (err != 0)
    {
      printf ("2nd key_create failed: %s\n", strerror (err));
      return 1;
    }

  if (key1 != key2)
    puts ("key1 != key2; no more tests performed");
  else
    {
      value = pthread_getspecific (key2);
      if (value != NULL)
       {
         puts ("4th getspecific != NULL");
         result = 1;
       }
    }

  return result;
}

Here is the call graph for this function: