Back to index

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

Go to the source code of this file.

Defines

#define TIMEOUT   5
#define TEST_FUNCTION   do_test ()

Functions

static void handler (int sig)
static void * tf (void *a)
int do_test (void)

Variables

static pthread_cond_t c = PTHREAD_COND_INITIALIZER
static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER
static pthread_barrier_t b

Define Documentation

#define TEST_FUNCTION   do_test ()

Definition at line 158 of file tst-kill3.c.

#define TIMEOUT   5

Definition at line 157 of file tst-kill3.c.


Function Documentation

int do_test ( void  )

Definition at line 89 of file tst-kill3.c.

{
  pthread_t th;

  struct sigaction sa;
  sigemptyset (&sa.sa_mask);
  sa.sa_flags = 0;
  sa.sa_handler = handler;
  if (sigaction (SIGUSR1, &sa, NULL) != 0)
    {
      puts ("sigaction failed");
      exit (1);
    }

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

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

  int e = pthread_barrier_wait (&b);
  if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
    {
      puts ("barrier_wait failed");
      exit (1);
    }

  if (pthread_mutex_lock (&m) != 0)
    {
      puts ("mutex_lock failed");
      exit (1);
    }

  /* Send the thread a signal which it has blocked.  */
  if (pthread_kill (th, SIGUSR1) != 0)
    {
      puts ("kill failed");
      exit (1);
    }

  if (pthread_mutex_unlock (&m) != 0)
    {
      puts ("mutex_unlock failed");
      exit (1);
    }

  void *r;
  if (pthread_join (th, &r) != 0)
    {
      puts ("join failed");
      exit (1);
    }
  if (r != NULL)
    {
      puts ("return value wrong");
      exit (1);
    }

  return 0;
}

Here is the call graph for this function:

static void handler ( int  sig) [static]

Definition at line 35 of file tst-kill3.c.

{
  write (1, "handler called\n", 15);
  _exit (1);
}

Here is the call graph for this function:

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

Definition at line 43 of file tst-kill3.c.

{
  /* Block SIGUSR1.  */
  sigset_t ss;

  sigemptyset (&ss);
  sigaddset (&ss, SIGUSR1);
  if (pthread_sigmask (SIG_BLOCK, &ss, NULL) != 0)
    {
      puts ("child: sigmask failed");
      exit (1);
    }

  if (pthread_mutex_lock (&m) != 0)
    {
      puts ("child: mutex_lock failed");
      exit (1);
    }

  int e = pthread_barrier_wait (&b);
  if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
    {
      puts ("child: barrier_wait failed");
      exit (1);
    }

  /* Compute timeout.  */
  struct timeval tv;
  (void) gettimeofday (&tv, NULL);
  struct timespec ts;
  TIMEVAL_TO_TIMESPEC (&tv, &ts);
  /* Timeout: 1sec.  */
  ts.tv_sec += 1;

  /* This call should never return.  */
  if (pthread_cond_timedwait (&c, &m, &ts) != ETIMEDOUT)
    {
      puts ("cond_timedwait didn't time out");
      exit (1);
    }

  return NULL;
}

Here is the call graph for this function:


Variable Documentation

pthread_barrier_t b [static]

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

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

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