Back to index

glibc  2.9
Defines | Functions | Variables
tst-cancel9.c File Reference
#include <fcntl.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 b

Define Documentation

#define TEST_FUNCTION   do_test ()

Definition at line 125 of file tst-cancel9.c.


Function Documentation

static void cleanup ( void *  arg) [static]

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

{
  fputs ("in cleanup\n", stdout);
}

Here is the call graph for this function:

static int do_test ( void  ) [static]

Definition at line 74 of file tst-cancel9.c.

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

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

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

  sleep (1);

  puts ("cancel now");

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

  puts ("waiting for the child");

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

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

  return 0;
}

Here is the call graph for this function:

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

Definition at line 39 of file tst-cancel9.c.

{
  int fd = open ("/dev/null", O_RDWR);
  if (fd == -1)
    {
      puts ("cannot open /dev/null");
      exit (1);
    }
  FILE *fp = fdopen (fd, "w");
  if (fp == NULL)
    {
      puts ("fdopen failed");
      exit (1);
    }

  pthread_cleanup_push (cleanup, NULL);

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

  while (1)
    /* fprintf() uses write() which is a cancallation point.  */
    fprintf (fp, "foo");

  pthread_cleanup_pop (0);

  return NULL;
}

Here is the call graph for this function:


Variable Documentation

pthread_barrier_t b [static]

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