Add 469782 to NEWS
[valgrind.git] / helgrind / tests / hg01_all_ok.c
blobb31df1d7b5f5da36ac11cd90b548789f2ae51ad4
1 /* All OK */
2 #include <stdlib.h>
3 #include <string.h>
4 #include <pthread.h>
6 static pthread_mutex_t mx = PTHREAD_MUTEX_INITIALIZER;
8 static int shared = 0;
9 static char *ptr;
11 static void breakme(void)
13 if (shared == 1)
14 memset (ptr, 0x55, 1000);
17 static void *th(void *v)
19 pthread_mutex_lock(&mx);
20 shared++;
21 if (shared == 1) {
22 ptr = malloc (1008);
23 breakme();
25 if (shared == 2) {
26 free (ptr);
27 breakme();
29 pthread_mutex_unlock(&mx);
31 return 0;
34 int main()
36 pthread_t a, b;
38 pthread_mutex_lock(&mx);
39 pthread_mutex_unlock(&mx);
41 pthread_create(&a, NULL, th, NULL);
42 pthread_create(&b, NULL, th, NULL);
44 pthread_join(a, NULL);
45 pthread_join(b, NULL);
47 return 0;