Back to index

glibc  2.9
Defines | Functions | Variables
tst-join2.c File Reference
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <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 103 of file tst-join2.c.


Function Documentation

static int do_test ( void  ) [static]

Definition at line 45 of file tst-join2.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;
  int val = pthread_tryjoin_np (th, &status);
  if (val == 0)
    {
      puts ("1st tryjoin succeeded");
      exit (1);
    }
  else if (val != EBUSY)
    {
      puts ("1st tryjoin didn't return EBUSY");
      exit (1);
    }

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

  while ((val = pthread_tryjoin_np (th, &status)) != 0)
    {
      if (val != EBUSY)
       {
         printf ("tryjoin returned %s (%d), expected only 0 or EBUSY\n",
                strerror (val), val);
         exit (1);
       }

      /* Delay minimally.  */
      struct timespec ts = { .tv_sec = 0, .tv_nsec = 10000000 };
      nanosleep (&ts, NULL);
    }

  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-join2.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-join2.c.