drd/tests/local_static: Fix a typo
[valgrind.git] / drd / tests / local_static.cpp
blob86c0fc1273c24d2cf1029d7d3244a409568cce05
1 // A C++ compiler is supposed to have thread-safe statics
3 #include <cstdio>
4 #include <vector>
5 #include <pthread.h>
7 class Singleton
9 public:
10 Singleton()
11 : value(42)
12 { }
14 int value;
17 void* thread_func(void*)
19 static Singleton singleton;
21 fprintf(stderr, "%d\n", singleton.value);
22 fprintf(stderr, "%d\n", singleton.value);
23 fprintf(stderr, "%d\n", singleton.value);
24 fprintf(stderr, "%d\n", singleton.value);
25 fprintf(stderr, "%d\n", singleton.value);
27 return 0;
30 int main(int, char**)
32 std::vector<pthread_t> thread(2);
33 void* v;
35 for (std::vector<pthread_t>::iterator p = thread.begin(); p != thread.end();
36 p++) {
37 if (pthread_create(&*p, 0, thread_func, 0) != 0) {
38 fprintf(stderr, "Creation of thread %ld failed\n",
39 &*p - &*thread.begin());
40 return 1;
44 for (std::vector<pthread_t>::const_iterator p = thread.begin();
45 p != thread.end(); p++) {
46 pthread_join(*p, &v);
49 fprintf(stderr, "Done.\n");
51 return 0;