Back to index

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

Go to the source code of this file.

Defines

#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_ERRORCHECK_MUTEX_INITIALIZER_NP

Define Documentation

#define TEST_FUNCTION   do_test ()

Definition at line 149 of file tst-cond9.c.


Function Documentation

static int do_test ( void  ) [static]

Definition at line 75 of file tst-cond9.c.

{
  pthread_t th;
  int err;

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

  err = pthread_cond_wait (&cond, &mut);
  if (err == 0)
    {
      puts ("cond_wait did not fail");
      exit (1);
    }

  if (err != EPERM)
    {
      printf ("cond_wait didn't return EPERM but %d\n", err);
      exit (1);
    }


  /* Current time.  */
  struct timeval tv;
  (void) gettimeofday (&tv, NULL);
  /* +1000 seconds in correct format.  */
  struct timespec ts;
  TIMEVAL_TO_TIMESPEC (&tv, &ts);
  ts.tv_sec += 1000;

  err = pthread_cond_timedwait (&cond, &mut, &ts);
  if (err == 0)
    {
      puts ("cond_timedwait did not fail");
      exit (1);
    }

  if (err != EPERM)
    {
      printf ("cond_timedwait didn't return EPERM but %d\n", err);
      exit (1);
    }

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

  puts ("creating thread");

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

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

  puts ("done");

  return 0;
}

Here is the call graph for this function:

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

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

{
  int err = pthread_cond_wait (&cond, &mut);
  if (err == 0)
    {
      puts ("cond_wait did not fail");
      exit (1);
    }

  if (err != EPERM)
    {
      printf ("cond_wait didn't return EPERM but %d\n", err);
      exit (1);
    }


  /* Current time.  */
  struct timeval tv;
  (void) gettimeofday (&tv, NULL);
  /* +1000 seconds in correct format.  */
  struct timespec ts;
  TIMEVAL_TO_TIMESPEC (&tv, &ts);
  ts.tv_sec += 1000;

  err = pthread_cond_timedwait (&cond, &mut, &ts);
  if (err == 0)
    {
      puts ("cond_timedwait did not fail");
      exit (1);
    }

  if (err != EPERM)
    {
      printf ("cond_timedwait didn't return EPERM but %d\n", err);
      exit (1);
    }

  return (void *) 1l;
}

Here is the call graph for this function:


Variable Documentation

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

pthread_mutex_t mut = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP [static]

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