Back to index

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

Go to the source code of this file.

Defines

#define N   16
#define TEST_FUNCTION   do_test ()

Functions

static void * tf (void *p)
static int do_test (void)

Variables

static int seen

Define Documentation

#define N   16

Definition at line 38 of file tst-stack1.c.

#define TEST_FUNCTION   do_test ()

Definition at line 96 of file tst-stack1.c.


Function Documentation

static int do_test ( void  ) [static]

Definition at line 41 of file tst-stack1.c.

{
  void *stack;
  int res = posix_memalign (&stack, getpagesize (), N * 4 * PTHREAD_STACK_MIN);
  if (res)
    {
      printf ("malloc failed %s\n", strerror (res));
      return 1;
    }

  pthread_attr_t attr;
  pthread_attr_init (&attr);

  int result = 0;
  for (int i = 0; i < N; ++i)
    {
      res = pthread_attr_setstack (&attr, stack + i * 4 * PTHREAD_STACK_MIN,
                               4 * PTHREAD_STACK_MIN);
      if (res)
       {
         printf ("pthread_attr_setstack failed %d\n", res);
         result = 1;
         continue;
       }

      /* Create the thread.  */
      pthread_t th;
      res = pthread_create (&th, &attr, tf, NULL);
      if (res)
       {
         printf ("pthread_create failed %d\n", res);
         result = 1;
       }
      else
       {
         res = pthread_join (th, NULL);
         if (res)
           {
             printf ("pthread_join failed %d\n", res);
             result = 1;
           }
       }
    }

  pthread_attr_destroy (&attr);

  if (seen != N)
    {
      printf ("seen %d != %d\n", seen, N);
      result = 1;
    }

  return result;
}

Here is the call graph for this function:

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

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

{
  ++seen;
  return NULL;
}

Variable Documentation

int seen [static]

Definition at line 29 of file tst-stack1.c.