Back to index

glibc  2.9
Functions | Variables
tst-cancel.c File Reference
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>

Go to the source code of this file.

Functions

static void cleanupok (void *arg)
static void innerok (int a)
static void * t4 (void *arg)
int main (int argc, char *argv[])

Variables

int fd
pthread_barrier_t bar
volatile int cleanupokcnt

Function Documentation

static void cleanupok ( void *  arg) [static]

Definition at line 62 of file tst-cancel.c.

{
  ++cleanupokcnt;
}

Here is the caller graph for this function:

static void innerok ( int  a) [static]

Definition at line 79 of file tst-cancel.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 98 of file tst-cancel.c.

{
  pthread_t td;
  int err;
  char *tmp;
  const char *prefix;
  const char template[] = "thtstXXXXXX";
  struct stat64 st;
  int result = 0;

  prefix = argc > 1 ? argv[1] : "";
  tmp = (char *) alloca (strlen (prefix) + sizeof template);
  strcpy (stpcpy (tmp, prefix), template);

  fd = mkstemp (tmp);
  if (fd == -1)
    {
      printf ("cannot create temporary file: %m");
      exit (1);
    }
  unlink (tmp);

  err = pthread_barrier_init (&bar, NULL, 2);
  if (err != 0 )
    {
      printf ("cannot create barrier: %s\n", strerror (err));
      exit (1);
    }

#ifdef NOT_YET
  err = pthread_create (&td, NULL, t1, NULL);
  if (err != 0)
    {
      printf ("cannot create thread t1: %s\n", strerror (err));
      exit (1);
    }

  err = pthread_join (td, NULL);
  if (err != 0)
    {
      printf ("cannot join thread: %s\n", strerror (err));
      exit (1);
    }

  err = pthread_create (&td, NULL, t2, (void *) 3);
  if (err != 0)
    {
      printf ("cannot create thread t2: %s\n", strerror (err));
      exit (1);
    }

  err = pthread_join (td, NULL);
  if (err != 0)
    {
      printf ("cannot join thread: %s\n", strerror (err));
      exit (1);
    }

  err = pthread_create (&td, NULL, t3, (void *) 5);
  if (err != 0)
    {
      printf ("cannot create thread t3: %s\n", strerror (err));
      exit (1);
    }

  err = pthread_join (td, NULL);
  if (err != 0)
    {
      printf ("cannot join thread: %s\n", strerror (err));
      exit (1);
    }
#endif

  err = pthread_create (&td, NULL, t4, (void *) 7);
  if (err != 0)
    {
      printf ("cannot create thread t4: %s\n", strerror (err));
      exit (1);
    }

  err = pthread_join (td, NULL);
  if (err != 0)
    {
      printf ("cannot join thread: %s\n", strerror (err));
      exit (1);
    }

  if (fstat64 (fd, &st) < 0)
    {
      printf ("cannot stat temporary file: %m\n");
      result = 1;
    }
  else if (st.st_size != 0)
    {
      char buf[512];
      puts ("some cleanup handlers ran:");
      fflush (stdout);
      __lseek (fd, 0, SEEK_SET);
      while (1)
       {
         ssize_t n = read (fd, buf, sizeof buf);
         if (n <= 0)
           break;
         write (STDOUT_FILENO, buf, n);
       }
      result = 1;
    }

  // if (cleanupokcnt != 3)  will be three once t3 runs
  if (cleanupokcnt != 2)
    {
      printf ("cleanupokcnt = %d\n", cleanupokcnt);
      result = 1;
    }

  return result;
}

Here is the call graph for this function:

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

Definition at line 88 of file tst-cancel.c.

{
  pthread_cleanup_push (cleanupok, (void *) (long int) 6);
  innerok ((int) (long int) arg);
  pthread_cleanup_pop (0);
  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

void bar

Definition at line 12 of file tst-cancel.c.

volatile int cleanupokcnt

Definition at line 59 of file tst-cancel.c.

Definition at line 10 of file tst-cancel.c.