llvm.org GIT mirror llvm / 91e22b0
unittests/SupportTests/Initialize.MultipleThreads: Appease --vg-leak to allocate stack explicitly for glibc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173350 91177308-0d34-0410-b5e6-96231b3b80d8 NAKAMURA Takumi 7 years ago
1 changed file(s) with 17 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
2525 *ms;
2626 return NULL;
2727 }
28
29 // Valgrind's leak checker complains glibc's stack allocation.
30 // To appease valgrind, we provide our own stack for each thread.
31 void *allocate_stack(pthread_attr_t &a, size_t n = 65536) {
32 void *stack = malloc(n);
33 pthread_attr_init(&a);
34 pthread_attr_setstack(&a, stack, n);
35 return stack;
36 }
2837 }
2938
3039 TEST(Initialize, MultipleThreads) {
3140 // Run this test under tsan: http://code.google.com/p/data-race-test/
3241
42 pthread_attr_t a1, a2;
43 void *p1 = test1::allocate_stack(a1);
44 void *p2 = test1::allocate_stack(a2);
45
3346 llvm_start_multithreaded();
3447 pthread_t t1, t2;
35 pthread_create(&t1, NULL, test1::helper, NULL);
36 pthread_create(&t2, NULL, test1::helper, NULL);
48 pthread_create(&t1, &a1, test1::helper, NULL);
49 pthread_create(&t2, &a2, test1::helper, NULL);
3750 pthread_join(t1, NULL);
3851 pthread_join(t2, NULL);
52 free(p1);
53 free(p2);
3954 llvm_stop_multithreaded();
4055 }
4156 #endif