2 * Test program that triggers strcpy() from one thread and a memory allocation
3 * immediately after the region read by strcpy() from another thread. Without
4 * strcpy() intercept there is about 50% chance that this test program triggers
5 * a false positive race report on Ubuntu 12.10 amd64.
7 * See also https://bugs.kde.org/show_bug.cgi?id=326436.
18 #if defined(__FreeBSD__)
24 #if defined(__FreeBSD__)
28 // https://stackoverflow.com/questions/4057319/is-setlocale-thread-safe-function
29 // setlocale is not thread safe, and indeed on FreeBSD
30 // a load of errors are generated if this is not guarded
31 void setlocale_wrapper()
33 const std::lock_guard
<std::mutex
> lock(g_mutex
);
34 setlocale(LC_ALL
, "English");
39 void setlocale_wrapper()
41 setlocale(LC_ALL
, "English");
50 ffList
.push_back((int *) NULL
);
51 for (list
<int*>::iterator ff
= ffList
.begin(); ff
!= ffList
.end(); ff
++) {
57 ffList
.push_back((int *) NULL
);
58 for (list
<int*>::const_iterator ff
= ffList
.begin(); ff
!= ffList
.end(); ff
++) {
68 subTest
= new SubTest();
74 for (size_t i
= 0; i
< 10000; i
++) {
84 void *func1(void *instance
)
86 Test
*casted
= reinterpret_cast<Test
*>(instance
);
93 void *func2(void *instance
)
95 Test
*casted
= reinterpret_cast<Test
*>(instance
);
102 int main(int argc
, char* argv
[])
111 err
= pthread_create(&thread1
, NULL
, &func1
, &instance1
);
113 throw string("failed to create a thread.");
114 err
= pthread_create(&thread2
, NULL
, &func2
, &instance2
);
116 throw string("failed to create a thread.");
118 err
= pthread_join(thread1
, NULL
);
120 throw string("Thread::join(): failed to join.");
121 err
= pthread_join(thread2
, NULL
);
123 throw string("Thread::join(): failed to join.");