2 /* I don't think this is a very good test .. all this
3 sleepery is highly confusing. */
5 /* test child thread inheriting data */
11 static volatile int shared
[2];
13 static void *t1(void *v
)
15 volatile int *ip
= (int *)v
;
16 if (0) printf("ta W\n");
23 static void *t2(void *v
)
25 volatile int *ip
= (int *)v
;
27 if (0) printf("tb W\n");
44 pthread_create(&a
, NULL
, t1
, (void *)&shared
[0]);
45 // a steals shared[0] from root thread, so is excl(a)
46 pthread_create(&b
, NULL
, t2
, (void *)&shared
[1]);
47 // b steals shared[1] from root thread, so is excl(b)
49 pthread_join(a
, NULL
);
50 // b's stuff (shared[1]) still belongs to b, so is excl(b)
52 // ret is excl(root), and shared[0] is re-acquired as excl(root)
53 // since a joined to root
54 if (0) printf("r R1\n");
55 ret
+= shared
[0]; /* no error - a is finished */
57 // but shared[1] is excl(b); hence we're reading excl(b)
58 // without a lock and without a dependency edge
59 if (0) printf("r R2\n");
60 ret
+= shared
[1]; /* expect error - b has not finished,
61 so we can't touch shared[1] yet */
63 pthread_join(b
, NULL
);