Back to index

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

Go to the source code of this file.

Defines

#define TEST_FUNCTION   do_test ()

Functions

static void * tf (void *p)
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 TEST_FUNCTION   do_test ()

Definition at line 93 of file tst-cond1.c.


Function Documentation

static int do_test ( void  ) [static]

Definition at line 56 of file tst-cond1.c.

{
  pthread_t th;
  int err;

  printf ("&cond = %p\n&mut = %p\n", &cond, &mut);

  puts ("parent: get mutex");

  err = pthread_mutex_lock (&mut);
  if (err != 0)
    error (EXIT_FAILURE, err, "parent: cannot get mutex");

  puts ("parent: create child");

  err = pthread_create (&th, NULL, tf, NULL);
  if (err != 0)
    error (EXIT_FAILURE, err, "parent: cannot create thread");

  puts ("parent: wait for condition");

  err = pthread_cond_wait (&cond, &mut);
  if (err != 0)
    error (EXIT_FAILURE, err, "parent: cannot wait fir signal");

  puts ("parent: got signal");

  err = pthread_join (th, NULL);
  if (err != 0)
    error (EXIT_FAILURE, err, "parent: failed to join");

  puts ("done");

  return 0;
}

Here is the call graph for this function:

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

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

{
  int err;

  err = pthread_mutex_lock (&mut);
  if (err != 0)
    error (EXIT_FAILURE, err, "child: cannot get mutex");

  puts ("child: got mutex; signalling");

  pthread_cond_signal (&cond);

  puts ("child: unlock");

  err = pthread_mutex_unlock (&mut);
  if (err != 0)
    error (EXIT_FAILURE, err, "child: cannot unlock");

  puts ("child: done");

  return NULL;
}

Here is the call graph for this function:


Variable Documentation

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

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