Back to index

glibc  2.9
Defines | Functions | Variables
tst-cond14.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 TEST_FUNCTION   do_test ()
#define TIMEOUT   3

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_RECURSIVE_MUTEX_INITIALIZER_NP
static pthread_mutex_t mut2 = PTHREAD_MUTEX_INITIALIZER

Define Documentation

#define TEST_FUNCTION   do_test ()

Definition at line 116 of file tst-cond14.c.

#define TIMEOUT   3

Definition at line 117 of file tst-cond14.c.


Function Documentation

static int do_test ( void  ) [static]

Definition at line 69 of file tst-cond14.c.

{
  if (pthread_mutex_lock (&mut2) != 0)
    {
      puts ("1st mutex_lock failed");
      return 1;
    }

  puts ("parent: create child");

  pthread_t th;
  int err = pthread_create (&th, NULL, tf, NULL);
  if (err != 0)
    {
      printf ("parent: cannot create thread: %s\n", strerror (err));
      return 1;
    }

  /* We have to synchronize with the child.  */
  if (pthread_mutex_lock (&mut2) != 0)
    {
      puts ("2nd mutex_lock failed");
      return 1;
    }

  /* Give the child to reach to pthread_cond_wait.  */
  sleep (1);

  if (pthread_cond_signal (&cond) != 0)
    {
      puts ("cond_signal failed");
      return 1;
    }

  err = pthread_join (th, NULL);
  if (err != 0)
    {
      printf ("parent: failed to join: %s\n", strerror (err));
      return 1;
    }

  puts ("done");

  return 0;
}

Here is the call graph for this function:

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

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

{
  if (pthread_mutex_lock (&mut) != 0)
    {
      printf ("%s: 1st mutex_lock failed\n", __func__);
      exit (1);
    }
  if (pthread_mutex_lock (&mut) != 0)
    {
      printf ("%s: 2nd mutex_lock failed\n", __func__);
      exit (1);
    }
  if (pthread_mutex_lock (&mut) != 0)
    {
      printf ("%s: 3rd mutex_lock failed\n", __func__);
      exit (1);
    }

  if (pthread_mutex_unlock (&mut2) != 0)
    {
      printf ("%s: mutex_unlock failed\n", __func__);
      exit (1);
    }

  if (pthread_cond_wait (&cond, &mut) != 0)
    {
      printf ("%s: cond_wait failed\n", __func__);
      exit (1);
    }

  puts ("child: done");

  return NULL;
}

Here is the call graph for this function:


Variable Documentation

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

pthread_mutex_t mut = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP [static]

Definition at line 28 of file tst-cond14.c.

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