bart | ea2a03c | 2010-03-21 17:24:47 +0000 | [diff] [blame] | 1 | // Test for ANNOTATE_BENIGN_RACE_STATIC() and ANNOTATE_UNPROTECTED_READ(). |
| 2 | |
| 3 | |
| 4 | #include <pthread.h> /* pthread_create() */ |
| 5 | #include <stdio.h> /* fprintf() */ |
| 6 | #include "../../drd/drd.h" |
| 7 | |
| 8 | |
| 9 | /* Local variables. */ |
| 10 | |
| 11 | static int s_i; |
| 12 | static volatile int s_j; |
| 13 | |
| 14 | ANNOTATE_BENIGN_RACE_STATIC(s_i, "Benign because duplicate assignment."); |
| 15 | |
| 16 | |
| 17 | /* Local functions. */ |
| 18 | |
bart | 9a02088 | 2010-09-11 10:07:56 +0000 | [diff] [blame] | 19 | static inline void AnnotateIgnoreReadsBegin() { ANNOTATE_IGNORE_READS_BEGIN(); } |
| 20 | static inline void AnnotateIgnoreReadsEnd() { ANNOTATE_IGNORE_READS_END(); } |
| 21 | |
bart | ea2a03c | 2010-03-21 17:24:47 +0000 | [diff] [blame] | 22 | static void* thread_func(void*) |
| 23 | { |
bart | 0af2b99 | 2010-09-13 17:44:10 +0000 | [diff] [blame] | 24 | #if defined(__powerpc__) && __GNUC__ -0 == 4 && __GNUC_MINOR__ -0 == 3 \ |
| 25 | && __GNUC_PATCHLEVEL__ -0 == 0 |
bart | 9a02088 | 2010-09-11 10:07:56 +0000 | [diff] [blame] | 26 | AnnotateIgnoreReadsBegin(); |
| 27 | int i = s_j; |
| 28 | AnnotateIgnoreReadsEnd(); |
| 29 | s_i = i; |
bart | 0af2b99 | 2010-09-13 17:44:10 +0000 | [diff] [blame] | 30 | #else |
| 31 | s_i = ANNOTATE_UNPROTECTED_READ(s_j); |
| 32 | #endif |
bart | ea2a03c | 2010-03-21 17:24:47 +0000 | [diff] [blame] | 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | int main(int argc, char** argv) |
| 37 | { |
| 38 | pthread_t tid; |
| 39 | |
| 40 | pthread_create(&tid, 0, thread_func, NULL); |
| 41 | s_j++; |
| 42 | s_i = s_j; |
| 43 | pthread_join(tid, NULL); |
| 44 | |
| 45 | fprintf(stderr, "Done.\n"); |
| 46 | |
| 47 | return 0; |
| 48 | } |