1 // A C++ compiler is supposed to have thread-safe statics
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
);
32 std::vector
<pthread_t
> thread(2);
35 for (std::vector
<pthread_t
>::iterator p
= thread
.begin(); p
!= thread
.end();
37 if (pthread_create(&*p
, 0, thread_func
, 0) != 0) {
38 fprintf(stderr
, "Creation of thread %d failed\n",
39 (int)(&*p
- &*thread
.begin()));
44 for (std::vector
<pthread_t
>::const_iterator p
= thread
.begin();
45 p
!= thread
.end(); p
++) {
49 fprintf(stderr
, "Done.\n");