From 58fbf5d6aa35e3d66f2c32c61d2f38824a990e85 Mon Sep 17 00:00:00 2001 From: otto Date: Sat, 20 Feb 2021 19:05:28 +0000 Subject: A regress test to test concurrent exception handling in threads --- regress/misc/exceptions/threads/Makefile | 11 ++++++ regress/misc/exceptions/threads/exceptions.cc | 52 +++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 regress/misc/exceptions/threads/Makefile create mode 100644 regress/misc/exceptions/threads/exceptions.cc (limited to 'regress/misc') 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 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 2021 Public Domain + */ + +#include +#include +#include +#include + +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; +} -- cgit v1.2.3-59-g8ed1b