Back to index

glibc  2.9
Defines | Functions | Variables
tst-cancel2.c File Reference
#include <pthread.h>
#include <signal.h>
#include <stdio.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

static int fd [2]

Define Documentation

#define TEST_FUNCTION   do_test ()

Definition at line 99 of file tst-cancel2.c.


Function Documentation

static int do_test ( void  ) [static]

Definition at line 47 of file tst-cancel2.c.

{
  pthread_t th;
  void *r;
  struct sigaction sa;

  sa.sa_handler = SIG_IGN;
  sigemptyset (&sa.sa_mask);
  sa.sa_flags = 0;

  if (sigaction (SIGPIPE, &sa, NULL) != 0)
    {
      puts ("sigaction failed");
      return 1;
    }

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

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

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

  /* This will cause the write in the child to return.  */
  close (fd[0]);

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

  if (r != PTHREAD_CANCELED)
    {
      printf ("result is wrong: expected %p, got %p\n", PTHREAD_CANCELED, r);
      return 1;
    }

  return 0;
}

Here is the call graph for this function:

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

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

{
  /* The buffer size must be larger than the pipe size so that the
     write blocks.  */
  char buf[100000];

  if (write (fd[1], buf, sizeof (buf)) == sizeof (buf))
    {
      puts ("write succeeded");
      return (void *) 1l;
    }

  return (void *) 42l;
}

Here is the call graph for this function:


Variable Documentation

int fd[2] [static]

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