Back to index

glibc  2.9
Classes | Defines | Functions | Variables
tst-cancel24.cc File Reference
#include <pthread.h>
#include <semaphore.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include "../test-skeleton.c"

Go to the source code of this file.

Classes

struct  monitor

Defines

#define TEST_FUNCTION   do_test ()
#define TIMEOUT   3

Functions

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

Variables

static volatile bool destr_called
static volatile bool except_caught
static pthread_barrier_t b

Define Documentation

#define TEST_FUNCTION   do_test ()

Definition at line 111 of file tst-cancel24.cc.

#define TIMEOUT   3

Definition at line 112 of file tst-cancel24.cc.


Function Documentation

static int do_test ( void  ) [static]

Definition at line 48 of file tst-cancel24.cc.

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

  sem_t s;
  if (sem_init (&s, 0, 0) != 0)
    {
      puts ("sem_init failed");
      return 1;
    }

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

  pthread_barrier_wait (&b);

  /* There is unfortunately no better method to try to assure the
     child thread reached the sem_wait call and is actually waiting
     than to sleep here.  */
  sleep (1);

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

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

  if (res != PTHREAD_CANCELED)
    {
      puts ("thread was not canceled");
      return 1;
    }

  if (! except_caught)
    {
      puts ("exception not caught");
      return 1;
    }

  if (! destr_called)
    {
      puts ("destructor not called");
      return 1;
    }

  return 0;
}

Here is the call graph for this function:

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

Definition at line 24 of file tst-cancel24.cc.

{
  sem_t *s = static_cast<sem_t *> (arg);

  try
    {
      monitor m;

      pthread_barrier_wait (&b);

      while (1)
      sem_wait (s);
    }
  catch (...)
    {
      except_caught = true;
      throw;
    }

  return NULL;
}

Here is the call graph for this function:


Variable Documentation

pthread_barrier_t b [static]

Definition at line 11 of file tst-cancel24.cc.

volatile bool destr_called [static]

Definition at line 8 of file tst-cancel24.cc.

volatile bool except_caught [static]

Definition at line 9 of file tst-cancel24.cc.