Back to index

glibc  2.9
Defines | Functions
tst-context.c File Reference
#include <tls.h>
#include <errno.h>
#include <error.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <ucontext.h>

Go to the source code of this file.

Defines

#define IS_IN_libpthread
#define N   4

Functions

int main (void)

Define Documentation

Definition at line 5 of file tst-context.c.

#define N   4

Definition at line 18 of file tst-context.c.


Function Documentation

int main ( void  )

Definition at line 71 of file tst-context.c.

{
#ifndef FLOATING_STACKS
  puts ("not supported");
  return 0;
#else
  int n;
  pthread_t th[N];
  ucontext_t mctx;

  puts ("making contexts");
  if (getcontext (&mctx) != 0)
    {
      if (errno == ENOSYS)
       {
         puts ("context handling not supported");
         exit (0);
       }

      printf ("%s: getcontext: %m\n", __FUNCTION__);
      exit (1);
    }

  /* Play some tricks with this context.  */
  if (++global == 1)
    if (setcontext (&mctx) != 0)
      {
       printf ("%s: setcontext: %m\n", __FUNCTION__);
       exit (1);
      }
  if (global != 2)
    {
      printf ("%s: 'global' not incremented twice\n", __FUNCTION__);
      exit (1);
    }

  for (n = 0; n < N; ++n)
    if (pthread_create (&th[n], NULL, threadfct, (void *) (long int) n) != 0)
      error (EXIT_FAILURE, errno, "cannot create all threads");

  for (n = 0; n < N; ++n)
    pthread_join (th[n], NULL);

  return failures;
#endif
}

Here is the call graph for this function: