Back to index

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

Go to the source code of this file.

Defines

#define N   10
#define EXPECTED_SIGNAL   SIGALRM
#define TEST_FUNCTION   do_test ()

Functions

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

Variables

static pthread_cond_t cond = PTHREAD_COND_INITIALIZER
static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER

Define Documentation

#define EXPECTED_SIGNAL   SIGALRM

Definition at line 111 of file tst-cond3.c.

#define N   10

Definition at line 36 of file tst-cond3.c.

#define TEST_FUNCTION   do_test ()

Definition at line 112 of file tst-cond3.c.


Function Documentation

static int do_test ( void  ) [static]

Definition at line 64 of file tst-cond3.c.

{
  int err;
  int i;

  for (i = 0; i < N; ++i)
    {
      pthread_t th;

      if (i != 0)
       {
         /* Release the mutex.  */
         err = pthread_mutex_unlock (&mut);
         if (err != 0)
           {
             printf ("mutex_unlock %d failed: %s\n", i, strerror (err));
             return 1;
           }
       }

      err = pthread_create (&th, NULL, tf, (void *) (long int) i);
      if (err != 0)
       {
         printf ("create %d failed: %s\n", i, strerror (err));
         return 1;
       }

      /* Get the mutex.  */
      err = pthread_mutex_lock (&mut);
      if (err != 0)
       {
         printf ("mutex_lock %d failed: %s\n", i, strerror (err));
         return 1;
       }
    }

  /* Set an alarm for 1 second.  The wrapper will expect this.  */
  alarm (1);

  /* This call should never return.  */
  pthread_cond_wait (&cond, &mut);

  puts ("cond_wait returned");
  return 1;
}

Here is the call graph for this function:

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

Definition at line 40 of file tst-cond3.c.

{
  int i = (long int) arg;
  int err;

  /* Get the mutex.  */
  err = pthread_mutex_lock (&mut);
  if (err != 0)
    {
      printf ("child %d mutex_lock failed: %s\n", i, strerror (err));
      exit (1);
    }

  /* This call should never return.  */
  pthread_cond_wait (&cond, &mut);

  /* We should never get here.  */
  exit (1);

  return NULL;
}

Here is the call graph for this function:


Variable Documentation

Definition at line 32 of file tst-cond3.c.

Definition at line 33 of file tst-cond3.c.