1 /*	$OpenBSD: exceptions.cc,v 1.1 2021/02/20 19:05:28 otto Exp $	*/
2 /*
3  *	Written by Otto Moerbeek <otto@drijf.net> 2021 Public Domain
4  */
5 
6 #include <string>
7 #include <iostream>
8 #include <err.h>
9 #include <pthread.h>
10 
11 void
12 a()
13 {
14 	try {
15 		throw std::string("foo");
16         }
17 	catch (const std::string& ex) {
18 		if (ex != "foo")
19 			errx(1, "foo");
20 	}
21 }
22 
23 void
24 b()
25 {
26 	a();
27 }
28 
29 void *
30 c(void *)
31 {
32 	b();
33 	return nullptr;
34 }
35 
36 #define N 100
37 
38 int
39 main()
40 {
41 	int i;
42 	pthread_t p[N];
43 
44 	for (i = 0; i < N; i++)
45 		if (pthread_create(&p[i], nullptr, c, nullptr) != 0)
46 			err(1, nullptr);
47 	for (i = 0; i < N; i++)
48 		if (pthread_join(p[i], nullptr) != 0)
49 			err(1, nullptr);
50 	std::cout << ".";
51 	return 0;
52 }
53