]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/thread-local-variables.dtest/main.c
3 // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/libfoo.dylib -install_name $RUN_DIR/libfoo.dylib
4 // BUILD: $CC main.c $BUILD_DIR/libfoo.dylib -o $BUILD_DIR/thread-local-variables.exe
7 // RUN: ./thread-local-variables.exe
17 #include "test_support.h"
19 extern __thread
int a
;
20 extern __thread
int b
;
21 static __thread
int c
;
22 static __thread
int d
= 5;
25 static int* sAddr1
[4];
26 static int* sAddr2
[4];
27 static int* sAddr3
[4];
29 static pthread_t sWorker1
;
30 static pthread_t sWorker2
;
33 // verify all initial TLV values are correct
34 static void checkValues()
43 // return addresses of all TLVs
44 static void getAddresses(int* array
[])
52 static void* work2(void* arg
)
60 static void* work1(void* arg
)
64 if ( pthread_create(&sWorker2
, NULL
, work2
, NULL
) != 0 ) {
65 FAIL("pthread_create");
68 pthread_join(sWorker2
, &dummy
);
75 static bool someMatch(int* t1
, int* t2
, int* t3
)
86 int main(int argc
, const char* argv
[], const char* envp
[], const char* apple
[]) {
89 if ( pthread_create(&sWorker1
, NULL
, work1
, NULL
) != 0 ) {
90 FAIL("pthread_create");
96 pthread_join(sWorker1
, &dummy
);
98 // validate each thread had different addresses for all TLVs
99 if ( someMatch(sAddr1
[0], sAddr2
[0], sAddr3
[0]) )
100 FAIL("&a is same across some threads");
101 else if ( someMatch(sAddr1
[1], sAddr2
[1], sAddr3
[1]) )
102 FAIL("&b is same across some threads");
103 else if ( someMatch(sAddr1
[2], sAddr2
[2], sAddr3
[2]) )
104 FAIL("&c is same across some threads");
105 else if ( someMatch(sAddr1
[3], sAddr2
[3], sAddr3
[3]) )
106 FAIL("&d is same across some threads");