Skip to content
Snippets Groups Projects
Commit cd0b86f9 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 6758c643
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,7 @@ const std::string OutputFileHandler::journal_file_ = "index.journal";
tbb::concurrent_bounded_queue<std::pair<std::string, FILE *>> OutputFileHandler::files_to_close_ =
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() {
if (current_file_ != 0) {
......@@ -86,7 +86,11 @@ void OutputFileHandler::close_and_rename::operator()() const {
// std::cout << std::this_thread::get_id() << " try pop" <<
// files_to_close_.size() << std::endl;
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 "
<< files_to_close_.size();
if (fclose(n.second) != 0) {
......
#ifndef OUTPUTFILEHANDLER_H
#define OUTPUTFILEHANDLER_H
#include <atomic>
#include <cstdint>
#include <cstdio>
#include <string>
......@@ -21,8 +22,8 @@ class OutputFileHandler {
current_file_(0),
close_and_rename_(base_path_),
t{} {
t = std::thread(close_and_rename_);
create_output_directory_maybe(working_files_base_path_);
t = std::thread(close_and_rename_);
}
~OutputFileHandler() {
......@@ -44,7 +45,8 @@ class OutputFileHandler {
std::string format_filename(uint32_t run_number, uint32_t index);
void exit_file_handler_loop() {
file_handler_running_ = false;
file_handler_running_.store(false, std::memory_order_release);
files_to_close_.abort();
t.join();
}
......@@ -66,7 +68,8 @@ class OutputFileHandler {
static const std::string journal_file_;
static tbb::concurrent_bounded_queue<std::pair<std::string, FILE *>> files_to_close_;
static bool file_handler_running_;
static std::atomic<bool> file_handler_running_;
std::string base_path_;
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