Back to index

glibc  2.9
Defines | Functions | Variables
tst-cancel12.c File Reference
#include <errno.h>
#include <pthread.h>
#include <semaphore.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 sem_t sem

Define Documentation

#define TEST_FUNCTION   do_test ()

Definition at line 126 of file tst-cancel12.c.


Function Documentation

static void cleanup ( void *  arg) [static]

Definition at line 34 of file tst-cancel12.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 72 of file tst-cancel12.c.

{
  pthread_t th;

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

  if (sem_init (&sem, 0, 1) != 0)
    {
      puts ("sem_init failed");
      exit (1);
    }

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

  /* Check whether cancellation is honored even before sem_wait does
     anything.  */
  if (pthread_cancel (th) != 0)
    {
      puts ("1st cancel failed");
      exit (1);
    }

  int e = pthread_barrier_wait (&bar);
  if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
    {
      puts ("1st barrier_wait 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 49 of file tst-cancel12.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.  */
  sem_wait (&sem);

  pthread_cleanup_pop (0);

  puts ("sem_wait returned");

  return NULL;
}

Here is the call graph for this function:


Variable Documentation

pthread_barrier_t bar [static]

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

sem_t sem [static]

Definition at line 30 of file tst-cancel12.c.