Добрый день!
Есть такой код:
std::atomic_int g_thr_cnt(0);
class Logger
{
public:
~Logger() {};
static Logger& get_logger()
{
static Logger logger;
return logger;
}
void log(const std::string& _msg)
{
m_messages.push_back(_msg);
}
void log_job(std::atomic_int& _counter)
{
while (_counter > 0)
{
cout << "Log job" << endl;
usleep(670000);
}
cout << "Logger exited" << endl;
}
protected:
std::list<std::string> m_messages;
Logger() {};
Logger(const Logger& _obj); // no copies
const Logger& operator=(const Logger& _obj); // no assignment
};
void sig_handler(int _sig)
{
switch (_sig)
{
case SIGTERM:
{
cout << "Got SIGTERM" << endl;
}
g_thr_cnt = 0;
break;
default:
cout << "No, no, no, David Blaine, no street magic!" << endl;
}
}
int main()
{
g_thr_cnt = 1;
signal(SIGTERM, sig_handler);
Logger& logger = Logger::get_logger();
std::thread thr(&Logger::log_job, std::ref(logger), std::ref(g_thr_cnt));
thr.join();
cout << "[exited]" << endl;
return 0;
}
На хосте (CentOS stream, gcc (GCC) 8.5.020210514) он собирается и работает. Ок, идем на целевую ОС (Debian 8 в виртуалке, gcc (Debian 4.9.2-10) 4.9.2) и получаем ошибку:
Scanning dependencies of target thr
make[2]: Warning: File '/home/user/work/log-thr/src/main.cpp' has modification time 6673 s in the future
[ 50%] Building CXX object CMakeFiles/thr.dir/main.cpp.o
In file included from /usr/include/c++/4.9/thread:39:0,
from /home/user/work/log-thr/src/main.cpp:2:
/usr/include/c++/4.9/functional: In instantiation of ‘struct std::_Bind_simple<std::_Mem_fn<void (Logger::*)(std::__atomic_base<int>&)>(std::reference_wrapper<Logger>, std::reference_wrapper<std::__atomic_base<int> >)>’:
/usr/include/c++/4.9/thread:140:47: required from ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (Logger::*)(std::__atomic_base<int>&); _Args = {std::reference_wrapper<Logger>, std::reference_wrapper<std::__atomic_base<int> >}]’
/home/user/work/log-thr/src/main.cpp:77:76: required from here
/usr/include/c++/4.9/functional:1665:61: error: no type named ‘type’ in ‘class std::result_of<std::_Mem_fn<void (Logger::*)(std::__atomic_base<int>&)>(std::reference_wrapper<Logger>, std::reference_wrapper<std::__atomic_base<int> >)>’
typedef typename result_of<_Callable(_Args...)>::type result_type;
^
/usr/include/c++/4.9/functional:1695:9: error: no type named ‘type’ in ‘class std::result_of<std::_Mem_fn<void (Logger::*)(std::__atomic_base<int>&)>(std::reference_wrapper<Logger>, std::reference_wrapper<std::__atomic_base<int> >)>’
_M_invoke(_Index_tuple<_Indices...>)
^
CMakeFiles/thr.dir/build.make:62: recipe for target 'CMakeFiles/thr.dir/main.cpp.o' failed
make[2]: *** [CMakeFiles/thr.dir/main.cpp.o] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/thr.dir/all' failed
make[1]: *** [CMakeFiles/thr.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2
Кто-нибудь знает, как заставить код собираться?