1 /* Test program for the annotations that suppress both reads and writes. */
2
3 #include <assert.h> /* assert() */
4 #include <pthread.h>
5 #include <stdint.h>
6 #include <stdio.h> /* EOF */
7 #include <unistd.h> /* getopt() */
8 #include "../../drd/drd.h"
9
10 static int8_t s_a;
11 static int8_t s_b;
12 static int8_t s_c;
13
thread_func(void * arg)14 static void* thread_func(void* arg)
15 {
16 /* Read s_a and modify s_b. */
17 s_b = s_a;
18 /* Modify s_c. */
19 s_c = 1;
20
21 return NULL;
22 }
23
main(int argc,char ** argv)24 int main(int argc, char** argv)
25 {
26 const struct timespec delay = { 0, 100 * 1000 * 1000 };
27 int optchar;
28 int ign_rw = 1;
29 pthread_t tid;
30
31 while ((optchar = getopt(argc, argv, "r")) != EOF)
32 {
33 switch (optchar)
34 {
35 case 'r':
36 ign_rw = 0;
37 break;
38 default:
39 assert(0);
40 }
41 }
42
43 pthread_create(&tid, 0, thread_func, 0);
44
45 nanosleep(&delay, 0);
46
47 if (ign_rw)
48 ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN();
49 /* Read s_b and modify s_a. */
50 s_a = s_b;
51 if (ign_rw)
52 ANNOTATE_IGNORE_READS_AND_WRITES_END();
53
54 /*
55 * Insert a delay here in order to make sure the load of s_c happens
56 * after s_c has been modified.
57 */
58 sleep(1);
59
60 /* Read s_c. */
61 fprintf(stderr, "%s", "x" + s_c);
62
63 pthread_join(tid, 0);
64
65 fprintf(stderr, "Finished.\n");
66
67 return 0;
68 }
69