summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@yahooinc.com>2022-10-13 09:38:07 +0000
committerHåvard Pettersen <havardpe@yahooinc.com>2022-10-13 09:42:53 +0000
commit2f0711f74a175f6c932fdc4079ce74cf350fbafa (patch)
tree0f2d641aa14b5dcfb07d6f833b23e789951cb272 /vespalib
parent03892b4b7a5857471301aa40865c9767945fbd1a (diff)
add suppression and make safer
- add new valgrind suppression variant for leaked thread stack cache - hold lock while editing list of threads - use jthread for join in destructor
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/tests/coro/lazy/lazy_test.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/vespalib/src/tests/coro/lazy/lazy_test.cpp b/vespalib/src/tests/coro/lazy/lazy_test.cpp
index 4ba1c950ad0..3141d7a5363 100644
--- a/vespalib/src/tests/coro/lazy/lazy_test.cpp
+++ b/vespalib/src/tests/coro/lazy/lazy_test.cpp
@@ -4,18 +4,17 @@
#include <vespa/vespalib/coro/sync_wait.h>
#include <vespa/vespalib/util/require.h>
#include <vespa/vespalib/gtest/gtest.h>
+#include <mutex>
#include <thread>
using vespalib::coro::Lazy;
using vespalib::coro::sync_wait;
-std::vector<std::thread> threads;
+std::mutex thread_lock;
+std::vector<std::jthread> threads;
struct JoinThreads {
~JoinThreads() {
- for (auto &thread: threads) {
- thread.join();
- }
threads.clear();
}
};
@@ -24,7 +23,8 @@ auto run_in_other_thread() {
struct awaiter {
bool await_ready() const noexcept { return false; }
void await_suspend(std::coroutine_handle<> handle) const {
- threads.push_back(std::thread(handle));
+ auto guard = std::lock_guard(thread_lock);
+ threads.push_back(std::jthread(handle));
}
void await_resume() const noexcept {}
};