]>
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
18 extern __thread
int a
;
19 extern __thread
int b
;
20 static __thread
int c
;
21 static __thread
int d
= 5;
24 static int* sAddr1
[4];
25 static int* sAddr2
[4];
26 static int* sAddr3
[4];
28 static pthread_t sWorker1
;
29 static pthread_t sWorker2
;
32 // verify all initial TLV values are correct
33 static void checkValues()
42 // return addresses of all TLVs
43 static void getAddresses(int* array
[])
51 static void* work2(void* arg
)
59 static void* work1(void* arg
)
63 if ( pthread_create(&sWorker2
, NULL
, work2
, NULL
) != 0 ) {
64 printf("[FAIL] thread-local-variables, pthread_create\n");
68 pthread_join(sWorker2
, &dummy
);
75 static bool someMatch(int* t1
, int* t2
, int* t3
)
88 printf("[BEGIN] thread-local-variables\n");
92 if ( pthread_create(&sWorker1
, NULL
, work1
, NULL
) != 0 ) {
93 printf("[FAIL] thread-local-variables, pthread_create\n");
100 pthread_join(sWorker1
, &dummy
);
102 // validate each thread had different addresses for all TLVs
103 if ( someMatch(sAddr1
[0], sAddr2
[0], sAddr3
[0]) )
104 printf("[FAIL] thread-local-variables, &a is same across some threads\n");
105 else if ( someMatch(sAddr1
[1], sAddr2
[1], sAddr3
[1]) )
106 printf("[FAIL] thread-local-variables, &b is same across some threads\n");
107 else if ( someMatch(sAddr1
[2], sAddr2
[2], sAddr3
[2]) )
108 printf("[FAIL] thread-local-variables, &c is same across some threads\n");
109 else if ( someMatch(sAddr1
[3], sAddr2
[3], sAddr3
[3]) )
110 printf("[FAIL] thread-local-variables, &d is same across some threads\n");
112 printf("[PASS] thread-local-variables\n");