blob: 1202781702ced6ac6caae453d5e11989327a16af [file] [log] [blame]
bart5f3be752009-08-11 15:00:54 +00001/* Test program for the annotations that suppress both reads and writes. */
2
3#include <assert.h> /* assert() */
4#include <pthread.h>
bartde60fe52011-10-05 13:10:30 +00005#include <stdint.h>
bart5f3be752009-08-11 15:00:54 +00006#include <stdio.h> /* EOF */
7#include <unistd.h> /* getopt() */
8#include "../../drd/drd.h"
9
bartde60fe52011-10-05 13:10:30 +000010static int8_t s_a;
11static int8_t s_b;
12static int8_t s_c;
bart5f3be752009-08-11 15:00:54 +000013
14static void* thread_func(void* arg)
15{
16 /* Read s_a and modify s_b. */
17 s_b = s_a;
bartbcc84492009-08-12 07:03:30 +000018 /* Modify s_c. */
19 s_c = 1;
bart5f3be752009-08-11 15:00:54 +000020
21 return NULL;
22}
23
24int main(int argc, char** argv)
25{
bartcfca2d42011-07-28 09:33:55 +000026 const struct timespec delay = { 0, 100 * 1000 * 1000 };
bart5f3be752009-08-11 15:00:54 +000027 int optchar;
28 int ign_rw = 1;
29 pthread_t tid;
bart31b983d2010-02-21 14:52:59 +000030
bart5f3be752009-08-11 15:00:54 +000031 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);
bartcfca2d42011-07-28 09:33:55 +000044
45 nanosleep(&delay, 0);
46
bart5f3be752009-08-11 15:00:54 +000047 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();
bartbcc84492009-08-12 07:03:30 +000053
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. */
sewardj6d06b392011-04-21 23:05:49 +000061 fprintf(stderr, "%s", "x" + s_c);
bartbcc84492009-08-12 07:03:30 +000062
bart5f3be752009-08-11 15:00:54 +000063 pthread_join(tid, 0);
64
65 fprintf(stderr, "Finished.\n");
66
67 return 0;
68}