| bart | 5f3be75 | 2009-08-11 15:00:54 +0000 | [diff] [blame] | 1 | /* 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 |  | 
|  | 9 | static int s_a; | 
|  | 10 | static int s_b; | 
| bart | bcc8449 | 2009-08-12 07:03:30 +0000 | [diff] [blame] | 11 | static int s_c; | 
| bart | 5f3be75 | 2009-08-11 15:00:54 +0000 | [diff] [blame] | 12 |  | 
|  | 13 | static void* thread_func(void* arg) | 
|  | 14 | { | 
|  | 15 | /* Read s_a and modify s_b. */ | 
|  | 16 | s_b = s_a; | 
| bart | bcc8449 | 2009-08-12 07:03:30 +0000 | [diff] [blame] | 17 | /* Modify s_c. */ | 
|  | 18 | s_c = 1; | 
| bart | 5f3be75 | 2009-08-11 15:00:54 +0000 | [diff] [blame] | 19 |  | 
|  | 20 | return NULL; | 
|  | 21 | } | 
|  | 22 |  | 
|  | 23 | int main(int argc, char** argv) | 
|  | 24 | { | 
|  | 25 | int optchar; | 
|  | 26 | int ign_rw = 1; | 
| bart | bcc8449 | 2009-08-12 07:03:30 +0000 | [diff] [blame] | 27 | int tmp; | 
| bart | 5f3be75 | 2009-08-11 15:00:54 +0000 | [diff] [blame] | 28 | pthread_t tid; | 
| bart | 31b983d | 2010-02-21 14:52:59 +0000 | [diff] [blame] | 29 |  | 
| bart | 5f3be75 | 2009-08-11 15:00:54 +0000 | [diff] [blame] | 30 | while ((optchar = getopt(argc, argv, "r")) != EOF) | 
|  | 31 | { | 
|  | 32 | switch (optchar) | 
|  | 33 | { | 
|  | 34 | case 'r': | 
|  | 35 | ign_rw = 0; | 
|  | 36 | break; | 
|  | 37 | default: | 
|  | 38 | assert(0); | 
|  | 39 | } | 
|  | 40 | } | 
|  | 41 |  | 
|  | 42 | pthread_create(&tid, 0, thread_func, 0); | 
|  | 43 | if (ign_rw) | 
|  | 44 | ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN(); | 
|  | 45 | /* Read s_b and modify s_a. */ | 
|  | 46 | s_a = s_b; | 
|  | 47 | if (ign_rw) | 
|  | 48 | ANNOTATE_IGNORE_READS_AND_WRITES_END(); | 
| bart | bcc8449 | 2009-08-12 07:03:30 +0000 | [diff] [blame] | 49 |  | 
|  | 50 | /* | 
|  | 51 | * Insert a delay here in order to make sure the load of s_c happens | 
|  | 52 | * after s_c has been modified. | 
|  | 53 | */ | 
|  | 54 | sleep(1); | 
|  | 55 |  | 
|  | 56 | /* Read s_c. */ | 
|  | 57 | tmp = s_c; | 
|  | 58 |  | 
| bart | 5f3be75 | 2009-08-11 15:00:54 +0000 | [diff] [blame] | 59 | pthread_join(tid, 0); | 
|  | 60 |  | 
|  | 61 | fprintf(stderr, "Finished.\n"); | 
|  | 62 |  | 
|  | 63 | return 0; | 
|  | 64 | } |