Back to index

glibc  2.9
Defines | Functions | Variables
tst-cancel11.c File Reference
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "../test-skeleton.c"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define TEST_FUNCTION   do_test ()

Functions

static void cleanup (void *arg)
static void * tf (void *arg)
static int do_test (void)

Variables

static pthread_barrier_t bar
static int fd [2]

Define Documentation

#define TEST_FUNCTION   do_test ()

Definition at line 122 of file tst-cancel11.c.


Function Documentation

static void cleanup ( void *  arg) [static]

Definition at line 33 of file tst-cancel11.c.

{
  static int ncall;

  if (++ncall != 1)
    {
      puts ("second call to cleanup");
      exit (1);
    }

  printf ("cleanup call #%d\n", ncall);
}

Here is the call graph for this function:

static int do_test ( void  ) [static]

Definition at line 70 of file tst-cancel11.c.

{
  pthread_t th;

  if (pthread_barrier_init (&bar, NULL, 2) != 0)
    {
      puts ("barrier_init failed");
      exit (1);
    }

  if (pipe (fd) != 0)
    {
      puts ("pipe failed");
      exit (1);
    }

  if (pthread_create (&th, NULL, tf, NULL) != 0)
    {
      puts ("create failed");
      exit (1);
    }

  int e = pthread_barrier_wait (&bar);
  if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
    {
      puts ("1st barrier_wait failed");
      exit (1);
    }

  if (pthread_cancel (th) != 0)
    {
      puts ("1st cancel failed");
      exit (1);
    }

  void *r;
  if (pthread_join (th, &r) != 0)
    {
      puts ("join failed");
      exit (1);
    }

  if (r != PTHREAD_CANCELED)
    {
      puts ("thread not canceled");
      exit (1);
    }

  return 0;
}

Here is the call graph for this function:

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

Definition at line 48 of file tst-cancel11.c.

{
  pthread_cleanup_push (cleanup, NULL);

  int e = pthread_barrier_wait (&bar);
  if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
    {
      puts ("tf: 1st barrier_wait failed");
      exit (1);
    }

  /* This call should block and be cancelable.  */
  char buf[20];
  read (fd[0], buf, sizeof (buf));

  pthread_cleanup_pop (0);

  return NULL;
}

Here is the call graph for this function:


Variable Documentation

pthread_barrier_t bar [static]

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

int fd[2] [static]

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