6 /* Simple test program, no race: parent only modifies x after child
7 has modified it and then joined with the parent. Tests simple
8 thread lifetime segment handling. */
10 /* A simple function to "use" a value, so that gcc can't
11 possibly optimise it into nothing. */
12 static void use ( int x
) {
13 __asm__
__volatile__( "" : : "r"(x
) : "cc","memory" );
16 static void* worker_thread ( void* argV
)
18 int* arg
= (int*)argV
;
19 use(arg
[5]); /* read access */
26 volatile int* x
= malloc(10 * sizeof(int));
28 /* x[5] is Excl(parent) */
30 pthread_create(&thread_id
, 0, worker_thread
, (void*)x
);
32 use(x
[5]); /* read access */
34 /* Just before the threads join, x[5] is ShR (read by both parent
36 pthread_join(thread_id
, 0);
37 /* x[5] is Excl(parent), because only parent and child accessed it
38 and child has merged to parent. So now it's ok for parent to
39 access it without locking. */
41 x
[5] = 0; /* write access */