blob: c57117d99173af22e62908ce15dded23940cfaed [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>
5#include <stdio.h> /* EOF */
6#include <unistd.h> /* getopt() */
7#include "../../drd/drd.h"
8
9static int s_a;
10static int s_b;
bartbcc84492009-08-12 07:03:30 +000011static int s_c;
bart5f3be752009-08-11 15:00:54 +000012
13static void* thread_func(void* arg)
14{
15 /* Read s_a and modify s_b. */
16 s_b = s_a;
bartbcc84492009-08-12 07:03:30 +000017 /* Modify s_c. */
18 s_c = 1;
bart5f3be752009-08-11 15:00:54 +000019
20 return NULL;
21}
22
23int main(int argc, char** argv)
24{
25 int optchar;
26 int ign_rw = 1;
27 pthread_t tid;
bart31b983d2010-02-21 14:52:59 +000028
bart5f3be752009-08-11 15:00:54 +000029 while ((optchar = getopt(argc, argv, "r")) != EOF)
30 {
31 switch (optchar)
32 {
33 case 'r':
34 ign_rw = 0;
35 break;
36 default:
37 assert(0);
38 }
39 }
40
41 pthread_create(&tid, 0, thread_func, 0);
42 if (ign_rw)
43 ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN();
44 /* Read s_b and modify s_a. */
45 s_a = s_b;
46 if (ign_rw)
47 ANNOTATE_IGNORE_READS_AND_WRITES_END();
bartbcc84492009-08-12 07:03:30 +000048
49 /*
50 * Insert a delay here in order to make sure the load of s_c happens
51 * after s_c has been modified.
52 */
53 sleep(1);
54
55 /* Read s_c. */
sewardj6d06b392011-04-21 23:05:49 +000056 fprintf(stderr, "%s", "x" + s_c);
bartbcc84492009-08-12 07:03:30 +000057
bart5f3be752009-08-11 15:00:54 +000058 pthread_join(tid, 0);
59
60 fprintf(stderr, "Finished.\n");
61
62 return 0;
63}