|
From: <sv...@va...> - 2014-06-09 06:54:47
|
Author: bart
Date: Mon Jun 9 06:54:30 2014
New Revision: 14009
Log:
drd/tests/local_static: Add
Added:
trunk/drd/tests/local_static.cpp
trunk/drd/tests/local_static.stderr.exp
trunk/drd/tests/local_static.vgtest
Modified:
trunk/drd/tests/Makefile.am
Modified: trunk/drd/tests/Makefile.am
==============================================================================
--- trunk/drd/tests/Makefile.am (original)
+++ trunk/drd/tests/Makefile.am Mon Jun 9 06:54:30 2014
@@ -128,6 +128,8 @@
linuxthreads_det.stdout.exp \
linuxthreads_det.stdout.exp-linuxthreads \
linuxthreads_det.vgtest \
+ local_static.stderr.exp \
+ local_static.vgtest \
matinv.stderr.exp \
matinv.stdout.exp \
matinv.vgtest \
@@ -340,6 +342,7 @@
free_is_write \
hold_lock \
linuxthreads_det \
+ local_static \
memory_allocation \
monitor_example \
new_delete \
@@ -458,6 +461,8 @@
annotate_static_SOURCES = annotate_static.cpp
+local_static_SOURCES = local_static.cpp
+
if HAVE_OPENMP
omp_matinv_CFLAGS = $(AM_CFLAGS) -fopenmp
omp_matinv_LDFLAGS = -fopenmp
Added: trunk/drd/tests/local_static.cpp
==============================================================================
--- trunk/drd/tests/local_static.cpp (added)
+++ trunk/drd/tests/local_static.cpp Mon Jun 9 06:54:30 2014
@@ -0,0 +1,53 @@
+// A C++ compiler is supposed to have thread-safe statics
+
+#include <cstdio>
+#include <vector>
+#include <pthread.h>
+
+class Singleton
+{
+public:
+ Singleton()
+ : value(42)
+ { }
+
+ int value;
+};
+
+void* thread_func(void*)
+{
+ static Singleton singleton;
+
+ fprintf(stderr, "%d\n", singleton.value);
+ fprintf(stderr, "%d\n", singleton.value);
+ fprintf(stderr, "%d\n", singleton.value);
+ fprintf(stderr, "%d\n", singleton.value);
+ fprintf(stderr, "%d\n", singleton.value);
+
+ return 0;
+}
+
+int main(int, char**)
+{
+ std::vector<pthread_t> thread(2);
+ void* v;
+
+ for (std::vector<pthread_t>::iterator p = thread.begin(); p != thread.end();
+ p++) {
+ if (pthread_create(&*p, 0, thread_func, 0) == 0) {
+ fprintf(stderr, "Creation of thread %ld failed\n",
+ &*p - &*thread.begin());
+ return 1;
+ }
+ }
+
+ for (std::vector<pthread_t>::const_iterator p = thread.begin();
+ p != thread.end(); p++) {
+ pthread_join(*p, &v);
+ }
+
+ fprintf(stderr, "Done.\n");
+
+ return 0;
+}
+
Added: trunk/drd/tests/local_static.stderr.exp
==============================================================================
(empty)
Added: trunk/drd/tests/local_static.vgtest
==============================================================================
--- trunk/drd/tests/local_static.vgtest (added)
+++ trunk/drd/tests/local_static.vgtest Mon Jun 9 06:54:30 2014
@@ -0,0 +1,4 @@
+prereq: test -e local_static && ./supported_libpthread
+vgopts: --check-stack-var=yes --show-confl-seg=no
+prog: local_static
+stderr_filter: filter_stderr
|