Skip to content
Snippets Groups Projects
Commit ae168dd0 authored by Emilio Meschi's avatar Emilio Meschi :bicyclist_tone1:
Browse files

fixes to avoid deadlocks in destructor in case of a fatal uncaught exception

parent 1b42bdd3
No related branches found
Tags 6.2.0
No related merge requests found
...@@ -10,7 +10,7 @@ const std::string OutputFileHandler::journal_file_ = "index.journal"; ...@@ -10,7 +10,7 @@ const std::string OutputFileHandler::journal_file_ = "index.journal";
tbb::concurrent_bounded_queue<std::pair<std::string, FILE *>> tbb::concurrent_bounded_queue<std::pair<std::string, FILE *>>
OutputFileHandler::files_to_close_ = OutputFileHandler::files_to_close_ =
tbb::concurrent_bounded_queue<std::pair<std::string, FILE *>>(); tbb::concurrent_bounded_queue<std::pair<std::string, FILE *>>();
bool OutputFileHandler::file_handler_running_ = true; std::atomic<bool> OutputFileHandler::file_handler_running_{true};
void OutputFileHandler::enqueue_current_file_for_close_and_move_maybe() { void OutputFileHandler::enqueue_current_file_for_close_and_move_maybe() {
if (current_file_ != 0) { if (current_file_ != 0) {
...@@ -93,7 +93,11 @@ void OutputFileHandler::close_and_rename::operator()() const { ...@@ -93,7 +93,11 @@ void OutputFileHandler::close_and_rename::operator()() const {
// std::cout << std::this_thread::get_id() << " try pop" << // std::cout << std::this_thread::get_id() << " try pop" <<
// files_to_close_.size() << std::endl; // files_to_close_.size() << std::endl;
LOG(TRACE) << "try pop now. queue size now " << files_to_close_.size(); LOG(TRACE) << "try pop now. queue size now " << files_to_close_.size();
files_to_close_.pop(n); try {
files_to_close_.pop(n);
} catch (tbb::user_abort &e) {
break;
}
LOG(TRACE) << "popping file: " << n.first << " for closing, queue size now " LOG(TRACE) << "popping file: " << n.first << " for closing, queue size now "
<< files_to_close_.size(); << files_to_close_.size();
if (fclose(n.second) != 0) { if (fclose(n.second) != 0) {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define OUTPUTFILEHANDLER_H #define OUTPUTFILEHANDLER_H
#include "tbb/concurrent_queue.h" #include "tbb/concurrent_queue.h"
#include <atomic>
#include <cstdint> #include <cstdint>
#include <cstdio> #include <cstdio>
#include <string> #include <string>
...@@ -17,8 +18,8 @@ public: ...@@ -17,8 +18,8 @@ public:
working_files_base_path_(base_path_ + "/" + working_dir_), working_files_base_path_(base_path_ + "/" + working_dir_),
current_run_number_(0), current_index_(0), current_filename_(""), current_run_number_(0), current_index_(0), current_filename_(""),
current_file_(0), close_and_rename_(base_path_), t{} { current_file_(0), close_and_rename_(base_path_), t{} {
t = std::thread(close_and_rename_);
create_output_directory_maybe(working_files_base_path_); create_output_directory_maybe(working_files_base_path_);
t = std::thread(close_and_rename_);
} }
~OutputFileHandler() { ~OutputFileHandler() {
...@@ -40,7 +41,8 @@ private: ...@@ -40,7 +41,8 @@ private:
std::string format_filename(uint32_t run_number, uint32_t index); std::string format_filename(uint32_t run_number, uint32_t index);
void exit_file_handler_loop() { void exit_file_handler_loop() {
file_handler_running_ = false; file_handler_running_.store(false, std::memory_order_release);
files_to_close_.abort();
t.join(); t.join();
} }
...@@ -63,7 +65,8 @@ private: ...@@ -63,7 +65,8 @@ private:
static tbb::concurrent_bounded_queue<std::pair<std::string, FILE *>> static tbb::concurrent_bounded_queue<std::pair<std::string, FILE *>>
files_to_close_; files_to_close_;
static bool file_handler_running_;
static std::atomic<bool> file_handler_running_;
std::string base_path_; std::string base_path_;
std::string filename_prefix_; std::string filename_prefix_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment