17 #include <condition_variable> 29 [[noreturn]]
void bar() {
30 throw std::runtime_error(
"hello");
33 [[noreturn]]
void foo() {
37 [[noreturn]]
void baz() {
53 TEST(ExceptionCounter, oneThread) {
57 for (
volatile int i = 0;
i < 10; ++
i) {
69 TEST(ExceptionCounter, testClearExceptionStatistics) {
77 TEST(ExceptionCounter, testDifferentStacks) {
84 TEST(ExceptionCounter, multyThreads) {
85 constexpr
size_t kNumIterations = 10000;
87 std::vector<std::thread>
threads;
88 threads.resize(kNumThreads);
92 std::condition_variable preparedBarrier;
93 std::condition_variable finishedBarrier;
94 int preparedThreads = 0;
95 bool finished =
false;
97 for (
auto&
t : threads) {
98 t = std::thread([&]() {
99 for (
size_t i = 0;
i < kNumIterations; ++
i) {
104 std::unique_lock<std::mutex>
lock(preparedMutex);
106 preparedBarrier.notify_one();
109 std::unique_lock<std::mutex>
lock(finishedMutex);
110 finishedBarrier.wait(lock, [&]() {
return finished; });
115 std::unique_lock<std::mutex>
lock(preparedMutex);
116 preparedBarrier.wait(
117 lock, [&]() {
return preparedThreads ==
kNumThreads; });
125 std::unique_lock<std::mutex>
lock(finishedMutex);
127 finishedBarrier.notify_all();
130 for (
auto&
t : threads) {
#define EXPECT_EQ(val1, val2)
static size_t const kNumThreads
TEST(ExceptionCounter, oneThread)
std::vector< std::thread::id > threads
auto lock(SynchronizedLocker...lockersIn) -> std::tuple< typename SynchronizedLocker::LockedPtr... >
MyException(char const *const what)
std::vector< ExceptionStats > getExceptionStatistics()