In one of the member functions (being accessed by multiple threads) of my class, I create a separate thread to compress huge log file (~1GB).
void Log::log (std::string message)
{
// Lock using mutex
std::lock_guard<std::mutex> lck(mtx);
_outputFile << message << std::endl;
_outputFile.flush();
_sequence_number++;
_curr_file_size = _outputFile.tellp();
if (_curr_file_size >= max_size) {
// Code to close the file stream, rename the file, and reopen
...
// Create an independent thread to compress the file since
// it takes some time to compress huge files.
if (!_log_compression_on)
{
std::thread(&Log::rotate_log, this, _logfile, _max_files, _compress).detach();
}
}
}
I don't want this new thread to receive signals such as SIGTERM, SIGHUP, etc., because the main process has already installed handlers for these signals.
I want to know how can I block some signals in the newly created std::thread.
void rotate_log (std::string logfile, uint32_t max_files, bool compress)
{
// How to block some signals such as SIGTERM, SIGHUP?
// Do other stuff.
}