Back to index

glibc  2.9
Defines | Functions
tst-tls1.c File Reference
#include <pthread.h>
#include <stdio.h>
#include <stdlib.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 121 of file tst-tls1.c.


Function Documentation

int do_test ( void  )

Definition at line 59 of file tst-tls1.c.

{
#if !HAVE___THREAD

  puts ("No __thread support in compiler, test skipped.");

  return 0;
#else

  if (s.a != INIT_A || s.b != INIT_B)
    {
      puts ("initial value of s in main thread wrong");
      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;
    }

#define N 10
  int i;
  for (i = 0; i < N; ++i)
    {
#define M 10
      pthread_t th[M];
      int j;
      for (j = 0; j < M; ++j, ++s.a)
       if (pthread_create (&th[j], &a, tf, NULL) != 0)
         {
           puts ("pthread_create failed");
           exit (1);
         }

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

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

  return 0;
#endif
}

Here is the call graph for this function: