Back to index

glibc  2.9
Defines | Functions | Variables
tst-join3.c File Reference
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.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_mutex_t lock = PTHREAD_MUTEX_INITIALIZER

Define Documentation

#define TEST_FUNCTION   do_test ()

Definition at line 122 of file tst-join3.c.


Function Documentation

static int do_test ( void  ) [static]

Definition at line 45 of file tst-join3.c.

{
  pthread_t th;

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

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

  void *status;
  struct timespec ts;
  struct timeval tv;
  (void) gettimeofday (&tv, NULL);
  TIMEVAL_TO_TIMESPEC (&tv, &ts);
  ts.tv_nsec += 200000000;
  if (ts.tv_nsec >= 1000000000)
    {
      ts.tv_nsec -= 1000000000;
      ++ts.tv_sec;
    }
  int val = pthread_timedjoin_np (th, &status, &ts);
  if (val == 0)
    {
      puts ("1st timedjoin succeeded");
      exit (1);
    }
  else if (val != ETIMEDOUT)
    {
      puts ("1st timedjoin didn't return ETIMEDOUT");
      exit (1);
    }

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

  while (1)
    {
      (void) gettimeofday (&tv, NULL);
      TIMEVAL_TO_TIMESPEC (&tv, &ts);
      ts.tv_nsec += 200000000;
      if (ts.tv_nsec >= 1000000000)
       {
         ts.tv_nsec -= 1000000000;
         ++ts.tv_sec;
       }

      val = pthread_timedjoin_np (th, &status, &ts);
      if (val == 0)
       break;

      if (val != ETIMEDOUT)
       {
         printf ("timedjoin returned %s (%d), expected only 0 or ETIMEDOUT\n",
                strerror (val), val);
         exit (1);
       }
    }

  if (status != (void *) 42l)
    {
      printf ("return value %p, expected %p\n", status, (void *) 42l);
      exit (1);
    }

  return 0;
}

Here is the call graph for this function:

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

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

{
  if (pthread_mutex_lock (&lock) != 0)
    {
      puts ("child: mutex_lock failed");
      return NULL;
    }

  return (void *) 42l;
}

Here is the call graph for this function:


Variable Documentation

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