blob: 700ec4f5cb31f8a7659f8b648191ba181ba17e72 [file] [log] [blame]
jsgf12475f62003-10-16 06:09:41 +00001/* test child thread inheriting data */
2
nethercote766eb762004-04-16 07:22:42 +00003// ***
4//
5// Helgrind should detect an error on line 48 for this test, but it doesn't!
6//
7// ***
8
jsgf12475f62003-10-16 06:09:41 +00009#include <pthread.h>
10#include <unistd.h>
11
12static volatile int shared[2];
13
14static void *t1(void *v)
15{
16 volatile int *ip = (int *)v;
jsgf12475f62003-10-16 06:09:41 +000017 *ip += 44;
18 *ip *= 2;
jsgf12475f62003-10-16 06:09:41 +000019 sleep(1);
jsgf12475f62003-10-16 06:09:41 +000020 return 0;
21}
22
23static void *t2(void *v)
24{
25 volatile int *ip = (int *)v;
jsgf12475f62003-10-16 06:09:41 +000026 *ip += 88;
27 *ip *= 3;
jsgf12475f62003-10-16 06:09:41 +000028 sleep(2);
jsgf12475f62003-10-16 06:09:41 +000029 return 0;
30}
31
32int main()
33{
34 pthread_t a, b;
35 volatile int ret = 0;
36
37 sleep(0);
38
39 shared[0] = 22;
40 shared[1] = 77;
41
42 pthread_create(&a, NULL, t1, (void *)&shared[0]);
43 pthread_create(&b, NULL, t2, (void *)&shared[1]);
44
45 pthread_join(a, NULL);
46
47 ret += shared[0]; /* no error - a is finished */
48 ret += shared[1]; /* expect error - b has not finished,
49 so we can't touch shared[1] yet */
50
51 pthread_join(b, NULL);
52
53
54 return ret;
55}