summaryrefslogtreecommitdiffstats
path: root/regress/misc
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2021-02-20 19:05:28 +0000
committerotto <otto@openbsd.org>2021-02-20 19:05:28 +0000
commit58fbf5d6aa35e3d66f2c32c61d2f38824a990e85 (patch)
tree80c0e0bc123e0a6f8859bfd58e1e3661efc427dc /regress/misc
parentMake the unwind cache tread-safe by declaring it thread_local. Solves (diff)
downloadwireguard-openbsd-58fbf5d6aa35e3d66f2c32c61d2f38824a990e85.tar.xz
wireguard-openbsd-58fbf5d6aa35e3d66f2c32c61d2f38824a990e85.zip
A regress test to test concurrent exception handling in threads
Diffstat (limited to 'regress/misc')
-rw-r--r--regress/misc/exceptions/threads/Makefile11
-rw-r--r--regress/misc/exceptions/threads/exceptions.cc52
2 files changed, 63 insertions, 0 deletions
diff --git a/regress/misc/exceptions/threads/Makefile b/regress/misc/exceptions/threads/Makefile
new file mode 100644
index 00000000000..722725b4f19
--- /dev/null
+++ b/regress/misc/exceptions/threads/Makefile
@@ -0,0 +1,11 @@
+# $OpenBSD: Makefile,v 1.1 2021/02/20 19:05:28 otto Exp $
+
+PROG= exceptions
+SRCS= exceptions.cc
+
+REGRESS_TARGETS=runs
+
+runs: exceptions
+ for i in $$(jot 100); do exceptions; done
+
+.include <bsd.regress.mk>
diff --git a/regress/misc/exceptions/threads/exceptions.cc b/regress/misc/exceptions/threads/exceptions.cc
new file mode 100644
index 00000000000..a29ac883d2a
--- /dev/null
+++ b/regress/misc/exceptions/threads/exceptions.cc
@@ -0,0 +1,52 @@
+/* $OpenBSD: exceptions.cc,v 1.1 2021/02/20 19:05:28 otto Exp $ */
+/*
+ * Written by Otto Moerbeek <otto@drijf.net> 2021 Public Domain
+ */
+
+#include <string>
+#include <iostream>
+#include <err.h>
+#include <pthread.h>
+
+void
+a()
+{
+ try {
+ throw std::string("foo");
+ }
+ catch (const std::string& ex) {
+ if (ex != "foo")
+ errx(1, "foo");
+ }
+}
+
+void
+b()
+{
+ a();
+}
+
+void *
+c(void *)
+{
+ b();
+ return nullptr;
+}
+
+#define N 100
+
+int
+main()
+{
+ int i;
+ pthread_t p[N];
+
+ for (i = 0; i < N; i++)
+ if (pthread_create(&p[i], nullptr, c, nullptr) != 0)
+ err(1, nullptr);
+ for (i = 0; i < N; i++)
+ if (pthread_join(p[i], nullptr) != 0)
+ err(1, nullptr);
+ std::cout << ".";
+ return 0;
+}