Add DRD suppression patterns for races triggered by std::ostream
[valgrind.git] / helgrind / tests / free_is_write.c
blob0dc53f8d1e4b02277b0bd3399181b99c7529e62a
2 #include <assert.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <pthread.h>
6 #include <unistd.h>
8 static char* s_mem;
10 /* wait a second, so as to guarantee that the parent access
11 the malloc'd area, then free it. */
12 static void* thread_func(void* arg)
14 sleep(1);
15 free(s_mem);
16 return NULL;
19 int main(int argc, char** argv)
21 pthread_t tid;
22 int quiet;
24 fprintf(stderr, "Start.\n");
26 quiet = argc > 1;
28 s_mem = malloc(10);
29 if (0 && !quiet)
30 fprintf(stderr, "Pointer to allocated memory: %p\n", s_mem);
31 assert(s_mem);
32 pthread_create(&tid, NULL, thread_func, NULL);
34 /* Write, which isn't coordinated with the free ==> a race
35 should be reported. */
36 char c = s_mem[5];
37 __asm__ __volatile__("" : : "r"((long)c) );
39 pthread_join(tid, NULL);
40 fprintf(stderr, "Done.\n");
41 return 0;