以下の最小のサンプルコードがあります。私がしようとしているのは、別のスレッドで を別のスレッドに入れて、boost::asio::deadline_timer
を開始するように、x msの関数loop
が呼び出され、何かが実行され、タイマーが再設定され、無限になるまで続きます。Valgrindエラー:Syscall param epoll_pwait(sigmask)がアドレス指定不可能なバイトを指している
#include <iostream>
#include <boost/asio.hpp>
#include <boost/thread/thread.hpp>
void wait(int milliseconds) {
boost::asio::io_service ioService;
boost::asio::deadline_timer timer(ioService, boost::posix_time::milliseconds(milliseconds));
timer.wait();
}
class Foo {
public:
boost::asio::io_service ioService;
boost::thread* thread = nullptr;
boost::posix_time::milliseconds duration;
boost::asio::deadline_timer timer;
bool shouldStop = false;
Foo() : ioService(), duration(10), timer(ioService, duration) {
}
~Foo() {
if (thread != nullptr) {
shouldStop = true;
wait(15);
ioService.stop();
thread->join();
delete thread;
thread = nullptr;
}
}
void start() {
timer.async_wait(boost::bind(&Foo::loop, this));
thread = new boost::thread([&](){ioService.run();});
}
void loop() {
if (shouldStop)
return;
timer.expires_at(timer.expires_at() + duration);
timer.async_wait(boost::bind(&Foo::loop, this));
}
};
int main() {
Foo foo;
foo.start();
wait(1000);
return 0;
}
ないはそれについて文句を言うんでしたにvalgrind
しばらく前にあなたはそれが正常に動作します
g++ -std=c++11 -Wall -pedantic -pthread -g -I. -L/usr/local/lib -L/usr/lib -lboost_system -lpthread -lboost_thread threaded-io-service.cpp -o threaded-io-service
でそれをコンパイルすることができ、そして私はかなり確信しています。私は最近更新しました。
==22212== Memcheck, a memory error detector
==22212== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==22212== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==22212== Command: ./threaded-io-service
==22212==
==22212== Thread 2:
==22212== Syscall param epoll_pwait(sigmask) points to unaddressable byte(s)
==22212== at 0x5E62326: epoll_pwait (in /usr/lib/libc-2.26.so)
==22212== by 0x111D50: boost::asio::detail::epoll_reactor::run(bool, boost::asio::detail::op_queue<boost::asio::detail::task_io_service_operation>&) (epoll_reactor.ipp:438)
==22212== by 0x112EE8: boost::asio::detail::task_io_service::do_run_one(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&, boost::asio::detail::task_io_service_thread_info&, boost::system::error_code const&) (task_io_service.ipp:356)
==22212== by 0x1129F0: boost::asio::detail::task_io_service::run(boost::system::error_code&) (task_io_service.ipp:149)
==22212== by 0x11322B: boost::asio::io_service::run() (io_service.ipp:59)
==22212== by 0x114C9C: Foo::start()::{lambda()#1}::operator()() const (threaded-io-service.cpp:35)
==22212== by 0x11E8FF: boost::detail::thread_data<Foo::start()::{lambda()#1}>::run() (thread.hpp:116)
==22212== by 0x526E44E: ??? (in /usr/lib/libboost_thread.so.1.65.1)
==22212== by 0x5045089: start_thread (in /usr/lib/libpthread-2.26.so)
==22212== by 0x5E621BE: clone (in /usr/lib/libc-2.26.so)
==22212== Address 0x0 is not stack'd, malloc'd or (recently) free'd
==22212==
==22212==
==22212== HEAP SUMMARY:
==22212== in use at exit: 0 bytes in 0 blocks
==22212== total heap usage: 31 allocs, 31 frees, 81,701 bytes allocated
==22212==
==22212== All heap blocks were freed -- no leaks are possible
==22212==
==22212== For counts of detected and suppressed errors, rerun with: -v
==22212== ERROR SUMMARY: 112 errors from 1 contexts (suppressed: 0 from 0)
これは本当に間違いですか?私はthis bug reportを見つけました。人々はvalgrindのバグかもしれないと思っています。
どのバージョンのgccとブースト? – sehe
ahリンクされたバグは、特定のglibcのバージョンに依存する可能性があることを示しています。その場合は、distributions/custom repos – sehe