Back to index

glibc  2.9
Defines | Functions | Variables
tst-robust8.c File Reference
#include <pthread.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include "../test-skeleton.c"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define PREPARE(argc, argv)   prepare ()
#define TEST_FUNCTION   do_test ()
#define TIMEOUT   5
#define N   100
#define THESIGNAL   SIGKILL
#define ROUNDS   5
#define THREADS   9

Functions

static void prepare (void)
static int do_test (void)
static void * tf (void *arg)
static void child (int round)

Variables

static int fd
static struct timespec = { 0, 0 }
static pthread_mutex_tmap

Define Documentation

#define N   100

Definition at line 23 of file tst-robust8.c.

#define PREPARE (   argc,
  argv 
)    prepare ()

Definition at line 15 of file tst-robust8.c.

#define ROUNDS   5

Definition at line 35 of file tst-robust8.c.

#define TEST_FUNCTION   do_test ()

Definition at line 17 of file tst-robust8.c.

#define THESIGNAL   SIGKILL

Definition at line 34 of file tst-robust8.c.

#define THREADS   9

Definition at line 36 of file tst-robust8.c.

#define TIMEOUT   5

Definition at line 18 of file tst-robust8.c.


Function Documentation

static void child ( int  round) [static]

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

{
  for (int thread = 1; thread <= THREADS; ++thread)
    {
      pthread_t th;
      if (pthread_create (&th, NULL, tf, (void *) (long int) thread) != 0)
       {
         printf ("cannot create thread %d in round %d\n", thread, round);
         exit (1);
       }
    }

  struct timespec ts;
  ts.tv_sec = 0;
  ts.tv_nsec = 1000000000 / ROUNDS;
  while (nanosleep (&ts, &ts) != 0)
    /* nothing */;

  /* Time to die.  */
  kill (getpid (), THESIGNAL);

  /* We better never get here.  */
  abort ();
}

Here is the call graph for this function:

static int do_test ( void  ) [static]
static void prepare ( void  ) [static]

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

{
  fd = create_temp_file ("tst-robust8", NULL);
  if (fd == -1)
    exit (1);
}

Here is the call graph for this function:

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

Definition at line 46 of file tst-robust8.c.

{
  long int nr = (long int) arg;
  int fct = nr % 3;

  uint8_t state[N];
  memset (state, '\0', sizeof (state));

  while (1)
    {
      int r = random () % N;
      if (state[r] == 0)
       {
         int e;

         switch (fct)
           {
           case 0:
             e = pthread_mutex_lock (&map[r]);
             if (e != 0)
              {
                printf ("mutex_lock of %d in thread %ld failed with %d\n",
                       r, nr, e);
                exit (1);
              }
             state[r] = 1;
             break;
           case 1:
             e = pthread_mutex_timedlock (&map[r], &before);
             if (e != 0 && e != ETIMEDOUT)
              {
                printf ("\
mutex_timedlock of %d in thread %ld failed with %d\n",
                       r, nr, e);
                exit (1);
              }
             break;
           default:
             e = pthread_mutex_trylock (&map[r]);
             if (e != 0 && e != EBUSY)
              {
                printf ("mutex_trylock of %d in thread %ld failed with %d\n",
                       r, nr, e);
                exit (1);
              }
             break;
           }

         if (e == EOWNERDEAD)
           pthread_mutex_consistent_np (&map[r]);

         if (e == 0 || e == EOWNERDEAD)
           state[r] = 1;
       }
      else
       {
         int e = pthread_mutex_unlock (&map[r]);
         if (e != 0)
           {
             printf ("mutex_unlock of %d in thread %ld failed with %d\n",
                    r, nr, e);
             exit (1);
           }

         state[r] = 0;
       }
    }
}

Here is the call graph for this function:


Variable Documentation

int fd [static]

Definition at line 22 of file tst-robust8.c.

pthread_mutex_t* map [static]

Definition at line 42 of file tst-robust8.c.

struct timespec = { 0, 0 } [static]

Definition at line 39 of file tst-robust8.c.