File: annotate_hb_err.c

package info (click to toggle)
valgrind 1%3A3.7.0-6
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 58,060 kB
  • sloc: ansic: 396,820; xml: 18,453; cpp: 6,698; asm: 5,584; perl: 5,008; sh: 4,852; makefile: 3,965; exp: 625; haskell: 195
file content (53 lines) | stat: -rw-r--r-- 1,208 bytes parent folder | download
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
/* Test program that triggers several happens-before usage errors. */


#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include "unified_annotations.h"


int main(int argc, char** argv)
{
  pthread_mutex_t m;
  pthread_cond_t  cv;
  int i[64];

  pthread_mutex_init(&m, NULL);
  pthread_cond_init(&cv, NULL);

  /* happens-after without preceding happens-before. */
  U_ANNOTATE_HAPPENS_AFTER(&i);

  /* happens-after on a mutex. */
  U_ANNOTATE_HAPPENS_BEFORE(&m);

  /* happens-after on a condition variable. */
  U_ANNOTATE_HAPPENS_BEFORE(&cv);

  /* condition variable operation on a h.b. annotated object. */
  U_ANNOTATE_HAPPENS_BEFORE(&i);
  pthread_cond_init((pthread_cond_t*)&i, NULL);

  /* The sequence below is fine. */
  U_ANNOTATE_NEW_MEMORY(&i, sizeof(i));
  U_ANNOTATE_HAPPENS_BEFORE(&i);
  U_ANNOTATE_HAPPENS_AFTER(&i);
  U_ANNOTATE_NEW_MEMORY(&i, sizeof(i));
  U_ANNOTATE_HAPPENS_BEFORE(&i);
  U_ANNOTATE_NEW_MEMORY(&i, sizeof(i));

  /* happens-before after happens-after. */
  U_ANNOTATE_HAPPENS_BEFORE(&i);
  U_ANNOTATE_HAPPENS_AFTER(&i);
  U_ANNOTATE_HAPPENS_BEFORE(&i);

  fprintf(stderr, "Done.\n");
  return 0;
}

/*
 * Local variables:
 * c-basic-offset: 2
 * End:
 */