1/* All OK */
2#include <stdlib.h>
3#include <string.h>
4#include <pthread.h>
5
6static pthread_mutex_t mx = PTHREAD_MUTEX_INITIALIZER;
7
8static int shared = 0;
9static char *ptr;
10
11static void breakme(void)
12{
13   if (shared == 1)
14      memset (ptr, 0x55, 1000);
15}
16
17static void *th(void *v)
18{
19	pthread_mutex_lock(&mx);
20	shared++;
21        if (shared == 1) {
22           ptr = malloc (1008);
23           breakme();
24        }
25        if (shared == 2) {
26           free (ptr);
27           breakme();
28        }
29	pthread_mutex_unlock(&mx);
30
31	return 0;
32}
33
34int main()
35{
36	pthread_t a, b;
37
38	pthread_mutex_lock(&mx);
39	pthread_mutex_unlock(&mx);
40
41	pthread_create(&a, NULL, th, NULL);
42	pthread_create(&b, NULL, th, NULL);
43
44	pthread_join(a, NULL);
45	pthread_join(b, NULL);
46
47	return 0;
48}
49