fortuna: thread -> jthread; add die_point latch
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
06deab6ef1
commit
680272bed4
11
fortuna.cpp
11
fortuna.cpp
@ -30,8 +30,8 @@ Fortuna::Fortuna() {
|
||||
|
||||
this->sync_point.wait(); // wait for init
|
||||
|
||||
th_sfm = std::thread(&Fortuna::seed_file_manager_service, this);
|
||||
th_urandom = std::thread(&Fortuna::urandom_entropy_src_service, this);
|
||||
th_sfm = std::jthread(&Fortuna::seed_file_manager_service, this);
|
||||
th_urandom = std::jthread(&Fortuna::urandom_entropy_src_service, this);
|
||||
}
|
||||
catch (CryptoPP::Exception& e) {
|
||||
fmt::print(stderr, "{}\n", e.what());
|
||||
@ -39,12 +39,7 @@ Fortuna::Fortuna() {
|
||||
}
|
||||
}
|
||||
Fortuna::~Fortuna() noexcept {
|
||||
if (th_sfm.joinable()) {
|
||||
th_sfm.join();
|
||||
}
|
||||
if (th_urandom.joinable()) {
|
||||
th_urandom.join();
|
||||
}
|
||||
fmt::print("[*] Fortuna says goodbye!\n");
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,8 +24,8 @@ public:
|
||||
std::mutex mtx_p_pools;
|
||||
mutable std::mutex mtx_accu; // used in const fun, too
|
||||
std::mutex print_mtx;
|
||||
std::thread th_sfm;
|
||||
std::thread th_urandom;
|
||||
std::jthread th_sfm;
|
||||
std::jthread th_urandom;
|
||||
|
||||
Fortuna();
|
||||
~Fortuna() noexcept;
|
||||
@ -114,6 +114,7 @@ public:
|
||||
std::make_shared<accumulator::Accumulator>()};
|
||||
|
||||
std::latch sync_point{1}; // wait for init before spawning the threads
|
||||
std::latch die_point{2}; // wait for service threads to die
|
||||
|
||||
}; // class Fortuna
|
||||
|
||||
|
Reference in New Issue
Block a user