Back to index

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

Go to the source code of this file.

Defines

#define TEST_FUNCTION   do_test ()

Functions

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

Variables

pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER
pthread_barrier_t b
int value = 0

Define Documentation

#define TEST_FUNCTION   do_test ()

Definition at line 110 of file tst-cancel7.c.


Function Documentation

static int do_test ( void  ) [static]

Definition at line 50 of file tst-cancel7.c.

{
  pthread_mutex_lock (&lock);

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

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

  int r = pthread_barrier_wait (&b);
  if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
    {
      printf ("%s: barrier_wait failed\n", __FUNCTION__);
      exit (1);
    }

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

  pthread_mutex_unlock (&lock);

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

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

  if (value == 0)
    {
      puts ("thread cancelled in the pthread_mutex_lock call");
      return 1;
    }

  if (value != 1)
    {
      puts ("thread not cancelled in pthread_testcancel call");
      return 1;
    }

  return 0;
}

Here is the call graph for this function:

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

Definition at line 31 of file tst-cancel7.c.

{
  int r = pthread_barrier_wait (&b);
  if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
    {
      printf ("%s: barrier_wait failed\n", __FUNCTION__);
      exit (1);
    }

  pthread_mutex_lock (&lock);
  ++value;
  pthread_testcancel ();
  ++value;
  pthread_mutex_unlock (&lock);
  return NULL;
}

Here is the call graph for this function:


Variable Documentation

pthread_barrier_t b

Definition at line 27 of file tst-cancel7.c.

Definition at line 26 of file tst-cancel7.c.

int value = 0

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