]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/valgrind/src/valgrind-3.6.0-svn/exp-ptrcheck/tests/pth_specific.c
update
[l4.git] / l4 / pkg / valgrind / src / valgrind-3.6.0-svn / exp-ptrcheck / tests / pth_specific.c
1 #include <pthread.h>
2 #include <assert.h>
3 #include <stdlib.h>
4
5 // This shows that putting a segment pointer into a thread-specific data
6 // area and then getting it out again doesn't lose info -- even though the
7 // key allocation/getting is done on the real CPU where the skin can't see,
8 // the get/set of the info is done using that key on the simd CPU where it
9 // can see, so everything works out fine.
10
11 int main(void)
12 {
13    pthread_key_t key;
14    char *x, *z;
15    char  y __attribute__((unused));
16
17    x = malloc(100);
18
19    y = x[-1];     // error
20    x[1] = 'z';
21
22    assert( 0 == pthread_key_create ( &key, NULL ) );
23    assert( 0 == pthread_setspecific(  key, x ) );
24    z = (char*)pthread_getspecific( key );
25    assert( 0 != z );
26
27    y = z[-1];     // error
28
29    // ensure the key went in and out correctly
30    assert(z == x);
31    assert(z[1] == 'z');
32
33    return 0;
34 }