File: tst-robust9.c

package info (click to toggle)
glibc 2.19-18+deb8u7
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 204,748 kB
  • sloc: ansic: 970,427; asm: 241,207; sh: 10,069; makefile: 8,476; cpp: 3,595; perl: 2,077; pascal: 1,839; awk: 1,704; yacc: 317; sed: 73
file content (94 lines) | stat: -rw-r--r-- 1,711 bytes parent folder | download | duplicates (50)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/time.h>


static pthread_mutex_t m;

static void *
tf (void *data)
{
  int err = pthread_mutex_lock (&m);
  if (err == EOWNERDEAD)
    {
      err = pthread_mutex_consistent_np (&m);
      if (err)
	{
	  puts ("pthread_mutex_consistent_np");
	  exit (1);
	}
    }
  else if (err)
    {
      puts ("pthread_mutex_lock");
      exit (1);
    }
  printf ("thread%ld got the lock.\n", (long int) data);
  sleep (1);
  /* exit without unlock */
  return NULL;
}

static int
do_test (void)
{
  int err, i;
  pthread_t t[3];
  pthread_mutexattr_t ma;

  pthread_mutexattr_init (&ma);
  err = pthread_mutexattr_setrobust_np (&ma, PTHREAD_MUTEX_ROBUST_NP);
  if (err)
    {
      puts ("pthread_mutexattr_setrobust_np");
      return 1;
    }
#ifdef ENABLE_PI
  if (pthread_mutexattr_setprotocol (&ma, PTHREAD_PRIO_INHERIT) != 0)
    {
      puts ("pthread_mutexattr_setprotocol failed");
      return 1;
    }
#endif
  err = pthread_mutex_init (&m, &ma);
#ifdef ENABLE_PI
  if (err == ENOTSUP)
    {
      puts ("PI robust mutexes not supported");
      return 0;
    }
#endif
  if (err)
    {
      puts ("pthread_mutex_init");
      return 1;
    }

  for (i = 0; i < sizeof (t) / sizeof (t[0]); i++)
    {
      err = pthread_create (&t[i], NULL, tf, (void *) (long int) i);
      if (err)
	{
	  puts ("pthread_create");
	  return 1;
	}
    }

  for (i = 0; i < sizeof (t) / sizeof (t[0]); i++)
    {
      err = pthread_join (t[i], NULL);
      if (err)
	{
	  puts ("pthread_join");
	  return 1;
	}
    }
  return 0;
}

#define TIMEOUT 5
#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"