boost asio HTTP Server 3 示例或 boost 错误中是不是存在错误?
Posted
技术标签:
【中文标题】boost asio HTTP Server 3 示例或 boost 错误中是不是存在错误?【英文标题】:Is there a bug in the boost asio HTTP Server 3 example or boost bug?boost asio HTTP Server 3 示例或 boost 错误中是否存在错误? 【发布时间】:2013-03-21 22:59:43 【问题描述】:boost 库版本 1.53 Debian Linux 6.0(x86_64 上的 Linux 2.6.32-5-amd64)
当 valgrind 日志包含大量警告时,很难测试自己的软件。 因此,在没有任何更改的情况下,我构建了 HTTP server3 示例并在 Valgrind 下运行它。 请看一看。我错过了什么吗?
valgrind --tool=helgrind --log-file=valgrind.log ./server3 0.0.0.0 83 5 /root/server3 这是 Helgrind 日志(编辑为 30000 个正文字符限制,完整日志http://pastebin.com/Vkbr9vsA):
Helgrind, a thread error detector
Copyright (C) 2007-2012, and GNU GPL'd, by OpenWorks LLP et al.
Using Valgrind-3.9.0.SVN and LibVEX; rerun with -h for copyright info
Command: ./server3 0.0.0.0 83 5 /root/server3
Parent PID: 8662
Lock at 0x524F5E0 was first observed
at 0x4C2C692: pthread_mutex_lock (hg_intercepts.c:495)
by 0x5043388: ??? (in /usr/lib/libboost_thread.so.1.53.0)
by 0x5043498: boost::detail::set_current_thread_data(boost::detail::thread_data_base*) (in /usr/lib/libboost_thread.so.1.53.0)
by 0x504380E: ??? (in /usr/lib/libboost_thread.so.1.53.0)
by 0x4C2D6FE: mythread_wrapper (hg_intercepts.c:219)
by 0x5256B4F: start_thread (pthread_create.c:304)
by 0x5CE5A7C: clone (clone.S:112)
Possible data race during read of size 8 at 0x524F4E8 by thread #3
Locks held: none
at 0x5043356: ??? (in /usr/lib/libboost_thread.so.1.53.0)
by 0x5043498: boost::detail::set_current_thread_data(boost::detail::thread_data_base*) (in /usr/lib/libboost_thread.so.1.53.0)
by 0x504380E: ??? (in /usr/lib/libboost_thread.so.1.53.0)
by 0x4C2D6FE: mythread_wrapper (hg_intercepts.c:219)
by 0x5256B4F: start_thread (pthread_create.c:304)
by 0x5CE5A7C: clone (clone.S:112)
This conflicts with a previous write of size 8 by thread #2
Locks held: 1, at address 0x524F5E0
at 0x5043416: ??? (in /usr/lib/libboost_thread.so.1.53.0)
by 0x5043498: boost::detail::set_current_thread_data(boost::detail::thread_data_base*) (in /usr/lib/libboost_thread.so.1.53.0)
by 0x504380E: ??? (in /usr/lib/libboost_thread.so.1.53.0)
by 0x4C2D6FE: mythread_wrapper (hg_intercepts.c:219)
by 0x5256B4F: start_thread (pthread_create.c:304)
by 0x5CE5A7C: clone (clone.S:112)
----------------------------------------------------------------
Possible data race during read of size 4 at 0x524F60C by thread #3
Locks held: none
at 0x50496D4: boost::detail::get_once_per_thread_epoch() (in /usr/lib/libboost_thread.so.1.53.0)
by 0x5043361: ??? (in /usr/lib/libboost_thread.so.1.53.0)
by 0x5043498: boost::detail::set_current_thread_data(boost::detail::thread_data_base*) (in /usr/lib/libboost_thread.so.1.53.0)
by 0x504380E: ??? (in /usr/lib/libboost_thread.so.1.53.0)
by 0x4C2D6FE: mythread_wrapper (hg_intercepts.c:219)
by 0x5256B4F: start_thread (pthread_create.c:304)
by 0x5CE5A7C: clone (clone.S:112)
This conflicts with a previous write of size 4 by thread #2
Locks held: none
at 0x525C27B: pthread_key_create (pthread_key_create.c:44)
by 0x525C82F: pthread_once (pthread_once.S:104)
by 0x50496D3: boost::detail::get_once_per_thread_epoch() (in /usr/lib/libboost_thread.so.1.53.0)
by 0x5043361: ??? (in /usr/lib/libboost_thread.so.1.53.0)
by 0x5043498: boost::detail::set_current_thread_data(boost::detail::thread_data_base*) (in /usr/lib/libboost_thread.so.1.53.0)
by 0x504380E: ??? (in /usr/lib/libboost_thread.so.1.53.0)
by 0x4C2D6FE: mythread_wrapper (hg_intercepts.c:219)
by 0x5256B4F: start_thread (pthread_create.c:304)
----------------------------------------------------------------
Possible data race during read of size 8 at 0x524F4E8 by thread #1
Locks held: 1, at address 0x61A1E20
at 0x5043356: ??? (in /usr/lib/libboost_thread.so.1.53.0)
by 0x5043478: boost::detail::get_current_thread_data() (in /usr/lib/libboost_thread.so.1.53.0)
by 0x5047875: boost::detail::interruption_checker::interruption_checker(pthread_mutex_t*, pthread_cond_t*) (in /usr/lib/libboost_thread.so.1.53.0)
by 0x5044002: boost::thread::join_noexcept() (in /usr/lib/libboost_thread.so.1.53.0)
by 0x42660E: boost::thread::join() (thread.hpp:751)
by 0x4215C5: http::server3::server::run() (server.cpp:63)
by 0x41A65B: main (main.cpp:37)
----------------------------------------------------------------
Possible data race during read of size 4 at 0x524F60C by thread #1
Locks held: 1, at address 0x61A1E20
at 0x50496D4: boost::detail::get_once_per_thread_epoch() (in /usr/lib/libboost_thread.so.1.53.0)
by 0x5043361: ??? (in /usr/lib/libboost_thread.so.1.53.0)
by 0x5043478: boost::detail::get_current_thread_data() (in /usr/lib/libboost_thread.so.1.53.0)
by 0x5047875: boost::detail::interruption_checker::interruption_checker(pthread_mutex_t*, pthread_cond_t*) (in /usr/lib/libboost_thread.so.1.53.0)
by 0x5044002: boost::thread::join_noexcept() (in /usr/lib/libboost_thread.so.1.53.0)
by 0x42660E: boost::thread::join() (thread.hpp:751)
by 0x4215C5: http::server3::server::run() (server.cpp:63)
by 0x41A65B: main (main.cpp:37)
This conflicts with a previous write of size 4 by thread #2
Locks held: none
at 0x525C27B: pthread_key_create (pthread_key_create.c:44)
by 0x525C82F: pthread_once (pthread_once.S:104)
by 0x50496D3: boost::detail::get_once_per_thread_epoch() (in /usr/lib/libboost_thread.so.1.53.0)
by 0x5043361: ??? (in /usr/lib/libboost_thread.so.1.53.0)
by 0x5043498: boost::detail::set_current_thread_data(boost::detail::thread_data_base*) (in /usr/lib/libboost_thread.so.1.53.0)
by 0x504380E: ??? (in /usr/lib/libboost_thread.so.1.53.0)
by 0x4C2D6FE: mythread_wrapper (hg_intercepts.c:219)
by 0x5256B4F: start_thread (pthread_create.c:304)
----------------------------------------------------------------
Possible data race during write of size 4 at 0x61A36B8 by thread #6
Locks held: none
at 0x4223B0: boost::asio::detail::epoll_reactor::descriptor_state::set_ready_events(unsigned int) (epoll_reactor.hpp:68)
by 0x4228A5: boost::asio::detail::epoll_reactor::run(bool, boost::asio::detail::op_queue<boost::asio::detail::task_io_service_operation>&) (epoll_reactor.ipp:430)
by 0x423629: 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:396)
by 0x423302: boost::asio::detail::task_io_service::run(boost::system::error_code&) (task_io_service.ipp:153)
by 0x42393A: boost::asio::io_service::run() (io_service.ipp:59)
by 0x42EB34: boost::_mfi::mf0<unsigned long, boost::asio::io_service>::operator()(boost::asio::io_service*) const (mem_fn_template.hpp:49)
by 0x42EA72: unsigned long boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> >::operator()<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list0>(boost::_bi::type<unsigned long>, boost::_mfi::mf0<unsigned long, boost::asio::io_service>&, boost::_bi::list0&, long) (bind.hpp:243)
by 0x42E91E: boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > >::operator()() (bind_template.hpp:20)
by 0x42E65D: boost::detail::thread_data<boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > > >::run() (thread.hpp:117)
by 0x5043818: ??? (in /usr/lib/libboost_thread.so.1.53.0)
by 0x4C2D6FE: mythread_wrapper (hg_intercepts.c:219)
by 0x5256B4F: start_thread (pthread_create.c:304)
Address 0x61A36B8 is 24 bytes inside a block of size 160 alloc'd
at 0x4C28A3A: operator new(unsigned long) (vg_replace_malloc.c:298)
by 0x42806A: boost::asio::detail::epoll_reactor::descriptor_state* boost::asio::detail::object_pool_access::create<boost::asio::detail::epoll_reactor::descriptor_state>() (object_pool.hpp:35)
by 0x4267B8: boost::asio::detail::object_pool<boost::asio::detail::epoll_reactor::descriptor_state>::alloc() (object_pool.hpp:89)
by 0x4229E3: boost::asio::detail::epoll_reactor::allocate_descriptor_state() (epoll_reactor.ipp:512)
by 0x4223D4: boost::asio::detail::epoll_reactor::register_descriptor(int, boost::asio::detail::epoll_reactor::descriptor_state*&) (epoll_reactor.ipp:151)
by 0x424405: boost::asio::detail::reactive_socket_service_base::do_assign(boost::asio::detail::reactive_socket_service_base::base_implementation_type&, int, int const&, boost::system::error_code&) (reactive_socket_service_base.ipp:182)
by 0x42DA98: boost::asio::detail::reactive_socket_service<boost::asio::ip::tcp>::assign(boost::asio::detail::reactive_socket_service<boost::asio::ip::tcp>::implementation_type&, boost::asio::ip::tcp const&, int const&, boost::system::error_code&) (reactive_socket_service.hpp:117)
by 0x42D75C: boost::asio::stream_socket_service<boost::asio::ip::tcp>::assign(boost::asio::detail::reactive_socket_service<boost::asio::ip::tcp>::implementation_type&, boost::asio::ip::tcp const&, int const&, boost::system::error_code&) (stream_socket_service.hpp:138)
by 0x42D263: boost::asio::basic_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >::assign(boost::asio::ip::tcp const&, int const&, boost::system::error_code&) (basic_socket.hpp:285)
by 0x42CAD7: boost::asio::detail::reactive_socket_accept_op_base<boost::asio::basic_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::asio::ip::tcp>::do_perform(boost::asio::detail::reactor_op*) (reactive_socket_accept_op.hpp:66)
by 0x409DE0: boost::asio::detail::reactor_op::perform() (reactor_op.hpp:40)
by 0x422C2F: boost::asio::detail::epoll_reactor::descriptor_state::perform_io(unsigned int) (epoll_reactor.ipp:622)
----------------------------------------------------------------
Possible data race during write of size 8 at 0x61A36A8 by thread #6
Locks held: none
at 0x410E9E: void boost::asio::detail::op_queue_access::next<boost::asio::detail::task_io_service_operation, boost::asio::detail::task_io_service_operation>(boost::asio::detail::task_io_service_operation*&, boost::asio::detail::task_io_service_operation*) (op_queue.hpp:41)
by 0x40EBEE: boost::asio::detail::op_queue<boost::asio::detail::task_io_service_operation>::push(boost::asio::detail::task_io_service_operation*) (op_queue.hpp:107)
by 0x4228BB: boost::asio::detail::epoll_reactor::run(bool, boost::asio::detail::op_queue<boost::asio::detail::task_io_service_operation>&) (epoll_reactor.ipp:431)
by 0x423629: 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:396)
by 0x423302: boost::asio::detail::task_io_service::run(boost::system::error_code&) (task_io_service.ipp:153)
by 0x42393A: boost::asio::io_service::run() (io_service.ipp:59)
by 0x42EB34: boost::_mfi::mf0<unsigned long, boost::asio::io_service>::operator()(boost::asio::io_service*) const (mem_fn_template.hpp:49)
by 0x42EA72: unsigned long boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> >::operator()<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list0>(boost::_bi::type<unsigned long>, boost::_mfi::mf0<unsigned long, boost::asio::io_service>&, boost::_bi::list0&, long) (bind.hpp:243)
by 0x42E91E: boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > >::operator()() (bind_template.hpp:20)
by 0x42E65D: boost::detail::thread_data<boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > > >::run() (thread.hpp:117)
by 0x5043818: ??? (in /usr/lib/libboost_thread.so.1.53.0)
by 0x4C2D6FE: mythread_wrapper (hg_intercepts.c:219)
Address 0x61A36A8 is 8 bytes inside a block of size 160 alloc'd
at 0x4C28A3A: operator new(unsigned long) (vg_replace_malloc.c:298)
by 0x42806A: boost::asio::detail::epoll_reactor::descriptor_state* boost::asio::detail::object_pool_access::create<boost::asio::detail::epoll_reactor::descriptor_state>() (object_pool.hpp:35)
by 0x4267B8: boost::asio::detail::object_pool<boost::asio::detail::epoll_reactor::descriptor_state>::alloc() (object_pool.hpp:89)
by 0x4229E3: boost::asio::detail::epoll_reactor::allocate_descriptor_state() (epoll_reactor.ipp:512)
by 0x4223D4: boost::asio::detail::epoll_reactor::register_descriptor(int, boost::asio::detail::epoll_reactor::descriptor_state*&) (epoll_reactor.ipp:151)
by 0x424405: boost::asio::detail::reactive_socket_service_base::do_assign(boost::asio::detail::reactive_socket_service_base::base_implementation_type&, int, int const&, boost::system::error_code&) (reactive_socket_service_base.ipp:182)
by 0x42DA98: boost::asio::detail::reactive_socket_service<boost::asio::ip::tcp>::assign(boost::asio::detail::reactive_socket_service<boost::asio::ip::tcp>::implementation_type&, boost::asio::ip::tcp const&, int const&, boost::system::error_code&) (reactive_socket_service.hpp:117)
by 0x42D75C: boost::asio::stream_socket_service<boost::asio::ip::tcp>::assign(boost::asio::detail::reactive_socket_service<boost::asio::ip::tcp>::implementation_type&, boost::asio::ip::tcp const&, int const&, boost::system::error_code&) (stream_socket_service.hpp:138)
by 0x42D263: boost::asio::basic_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >::assign(boost::asio::ip::tcp const&, int const&, boost::system::error_code&) (basic_socket.hpp:285)
by 0x42CAD7: boost::asio::detail::reactive_socket_accept_op_base<boost::asio::basic_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::asio::ip::tcp>::do_perform(boost::asio::detail::reactor_op*) (reactive_socket_accept_op.hpp:66)
by 0x409DE0: boost::asio::detail::reactor_op::perform() (reactor_op.hpp:40)
by 0x422C2F: boost::asio::detail::epoll_reactor::descriptor_state::perform_io(unsigned int) (epoll_reactor.ipp:622)
----------------------------------------------------------------
Thread #2: lock order "0x64C720 before 0x619E550" violated
Observed (incorrect) order is: acquisition of lock at 0x619E550
at 0x4C2C692: pthread_mutex_lock (hg_intercepts.c:495)
by 0x408545: boost::asio::detail::posix_mutex::lock() (posix_mutex.hpp:52)
by 0x40D9E1: boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>::scoped_lock(boost::asio::detail::posix_mutex&) (scoped_lock.hpp:36)
by 0x422BD3: boost::asio::detail::epoll_reactor::descriptor_state::perform_io(unsigned int) (epoll_reactor.ipp:611)
by 0x422D38: boost::asio::detail::epoll_reactor::descriptor_state::do_complete(boost::asio::detail::task_io_service*, boost::asio::detail::task_io_service_operation*, boost::system::error_code const&, unsigned long) (epoll_reactor.ipp:648)
by 0x409C69: boost::asio::detail::task_io_service_operation::complete(boost::asio::detail::task_io_service&, boost::system::error_code const&, unsigned long) (task_io_service_operation.hpp:37)
by 0x4236AD: 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:412)
by 0x423302: boost::asio::detail::task_io_service::run(boost::system::error_code&) (task_io_service.ipp:153)
by 0x42393A: boost::asio::io_service::run() (io_service.ipp:59)
by 0x42EB34: boost::_mfi::mf0<unsigned long, boost::asio::io_service>::operator()(boost::asio::io_service*) const (mem_fn_template.hpp:49)
by 0x42EA72: unsigned long boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> >::operator()<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list0>(boost::_bi::type<unsigned long>, boost::_mfi::mf0<unsigned long, boost::asio::io_service>&, boost::_bi::list0&, long) (bind.hpp:243)
by 0x42E91E: boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > >::operator()() (bind_template.hpp:20)
followed by a later acquisition of lock at 0x64C720
at 0x4C2C692: pthread_mutex_lock (hg_intercepts.c:495)
by 0x408845: boost::asio::detail::posix_static_mutex::lock() (posix_static_mutex.hpp:44)
by 0x40E523: boost::asio::detail::scoped_lock<boost::asio::detail::posix_static_mutex>::scoped_lock(boost::asio::detail::posix_static_mutex&) (scoped_lock.hpp:36)
by 0x424EE7: boost::asio::detail::signal_set_service::deliver_signal(int) (signal_set_service.ipp:431)
by 0x42477C: boost::asio::detail::signal_set_service::pipe_read_op::do_perform(boost::asio::detail::reactor_op*) (signal_set_service.ipp:95)
by 0x409DE0: boost::asio::detail::reactor_op::perform() (reactor_op.hpp:40)
by 0x422C2F: boost::asio::detail::epoll_reactor::descriptor_state::perform_io(unsigned int) (epoll_reactor.ipp:622)
by 0x422D38: boost::asio::detail::epoll_reactor::descriptor_state::do_complete(boost::asio::detail::task_io_service*, boost::asio::detail::task_io_service_operation*, boost::system::error_code const&, unsigned long) (epoll_reactor.ipp:648)
by 0x409C69: boost::asio::detail::task_io_service_operation::complete(boost::asio::detail::task_io_service&, boost::system::error_code const&, unsigned long) (task_io_service_operation.hpp:37)
by 0x4236AD: 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:412)
by 0x423302: boost::asio::detail::task_io_service::run(boost::system::error_code&) (task_io_service.ipp:153)
by 0x42393A: boost::asio::io_service::run() (io_service.ipp:59)
Required order was established by acquisition of lock at 0x64C720
at 0x4C2C692: pthread_mutex_lock (hg_intercepts.c:495)
by 0x408845: boost::asio::detail::posix_static_mutex::lock() (posix_static_mutex.hpp:44)
by 0x40E523: boost::asio::detail::scoped_lock<boost::asio::detail::posix_static_mutex>::scoped_lock(boost::asio::detail::posix_static_mutex&) (scoped_lock.hpp:36)
by 0x425060: boost::asio::detail::signal_set_service::add_service(boost::asio::detail::signal_set_service*) (signal_set_service.ipp:467)
by 0x4248BB: boost::asio::detail::signal_set_service::signal_set_service(boost::asio::io_service&) (signal_set_service.ipp:128)
by 0x42558B: boost::asio::signal_set_service::signal_set_service(boost::asio::io_service&) (signal_set_service.hpp:53)
by 0x42B628: boost::asio::io_service::service* boost::asio::detail::service_registry::create<boost::asio::signal_set_service>(boost::asio::io_service&) (service_registry.hpp:81)
by 0x408742: boost::asio::detail::service_registry::do_use_service(boost::asio::io_service::service::key const&, boost::asio::io_service::service* (*)(boost::asio::io_service&)) (service_registry.ipp:123)
by 0x42A92F: boost::asio::signal_set_service& boost::asio::detail::service_registry::use_service<boost::asio::signal_set_service>() (service_registry.hpp:48)
by 0x42984A: boost::asio::signal_set_service& boost::asio::use_service<boost::asio::signal_set_service>(boost::asio::io_service&) (io_service.hpp:33)
by 0x428633: boost::asio::basic_io_object<boost::asio::signal_set_service, false>::basic_io_object(boost::asio::io_service&) (basic_io_object.hpp:90)
by 0x42753A: boost::asio::basic_signal_set<boost::asio::signal_set_service>::basic_signal_set(boost::asio::io_service&) (basic_signal_set.hpp:106)
followed by a later acquisition of lock at 0x619E550
at 0x4C2C692: pthread_mutex_lock (hg_intercepts.c:495)
by 0x408545: boost::asio::detail::posix_mutex::lock() (posix_mutex.hpp:52)
by 0x40D9E1: boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>::scoped_lock(boost::asio::detail::posix_mutex&) (scoped_lock.hpp:36)
by 0x4224E4: boost::asio::detail::epoll_reactor::register_internal_descriptor(int, int, boost::asio::detail::epoll_reactor::descriptor_state*&, boost::asio::detail::reactor_op*) (epoll_reactor.ipp:179)
by 0x4250FC: boost::asio::detail::signal_set_service::add_service(boost::asio::detail::signal_set_service*) (signal_set_service.ipp:485)
by 0x4248BB: boost::asio::detail::signal_set_service::signal_set_service(boost::asio::io_service&) (signal_set_service.ipp:128)
by 0x42558B: boost::asio::signal_set_service::signal_set_service(boost::asio::io_service&) (signal_set_service.hpp:53)
by 0x42B628: boost::asio::io_service::service* boost::asio::detail::service_registry::create<boost::asio::signal_set_service>(boost::asio::io_service&) (service_registry.hpp:81)
by 0x408742: boost::asio::detail::service_registry::do_use_service(boost::asio::io_service::service::key const&, boost::asio::io_service::service* (*)(boost::asio::io_service&)) (service_registry.ipp:123)
by 0x42A92F: boost::asio::signal_set_service& boost::asio::detail::service_registry::use_service<boost::asio::signal_set_service>() (service_registry.hpp:48)
by 0x42984A: boost::asio::signal_set_service& boost::asio::use_service<boost::asio::signal_set_service>(boost::asio::io_service&) (io_service.hpp:33)
by 0x428633: boost::asio::basic_io_object<boost::asio::signal_set_service, false>::basic_io_object(boost::asio::io_service&) (basic_io_object.hpp:90)
----------------------------------------------------------------
Thread #1: lock order "0x619E550 before 0x64C720" violated
Observed (incorrect) order is: acquisition of lock at 0x64C720
at 0x4C2C692: pthread_mutex_lock (hg_intercepts.c:495)
by 0x408845: boost::asio::detail::posix_static_mutex::lock() (posix_static_mutex.hpp:44)
by 0x40E523: boost::asio::detail::scoped_lock<boost::asio::detail::posix_static_mutex>::scoped_lock(boost::asio::detail::posix_static_mutex&) (scoped_lock.hpp:36)
by 0x425166: boost::asio::detail::signal_set_service::remove_service(boost::asio::detail::signal_set_service*) (signal_set_service.ipp:492)
by 0x4248F0: boost::asio::detail::signal_set_service::shutdown_service() (signal_set_service.ipp:138)
by 0x42564D: boost::asio::signal_set_service::shutdown_service() (signal_set_service.hpp:110)
by 0x41AA69: boost::asio::detail::service_registry::~service_registry() (service_registry.ipp:37)
by 0x41AB32: boost::asio::io_service::~io_service() (io_service.ipp:53)
by 0x41B178: http::server3::server::~server() (in /root/server3/server3)
by 0x41A66A: main (main.cpp:37)
followed by a later acquisition of lock at 0x619E550
at 0x4C2C692: pthread_mutex_lock (hg_intercepts.c:495)
by 0x408545: boost::asio::detail::posix_mutex::lock() (posix_mutex.hpp:52)
by 0x40D9E1: boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>::scoped_lock(boost::asio::detail::posix_mutex&) (scoped_lock.hpp:36)
by 0x40AC3A: boost::asio::detail::epoll_reactor::deregister_descriptor(int, boost::asio::detail::epoll_reactor::descriptor_state*&, bool) (epoll_reactor.ipp:307)
by 0x4251BC: boost::asio::detail::signal_set_service::remove_service(boost::asio::detail::signal_set_service*) (signal_set_service.ipp:499)
by 0x4248F0: boost::asio::detail::signal_set_service::shutdown_service() (signal_set_service.ipp:138)
by 0x42564D: boost::asio::signal_set_service::shutdown_service() (signal_set_service.hpp:110)
by 0x41AA69: boost::asio::detail::service_registry::~service_registry() (service_registry.ipp:37)
by 0x41AB32: boost::asio::io_service::~io_service() (io_service.ipp:53)
by 0x41B178: http::server3::server::~server() (in /root/server3/server3)
by 0x41A66A: main (main.cpp:37)
Required order was established by acquisition of lock at 0x619E550
at 0x4C2C692: pthread_mutex_lock (hg_intercepts.c:495)
by 0x408545: boost::asio::detail::posix_mutex::lock() (posix_mutex.hpp:52)
by 0x40D9E1: boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>::scoped_lock(boost::asio::detail::posix_mutex&) (scoped_lock.hpp:36)
by 0x422BD3: boost::asio::detail::epoll_reactor::descriptor_state::perform_io(unsigned int) (epoll_reactor.ipp:611)
by 0x422D38: boost::asio::detail::epoll_reactor::descriptor_state::do_complete(boost::asio::detail::task_io_service*, boost::asio::detail::task_io_service_operation*, boost::system::error_code const&, unsigned long) (epoll_reactor.ipp:648)
by 0x409C69: boost::asio::detail::task_io_service_operation::complete(boost::asio::detail::task_io_service&, boost::system::error_code const&, unsigned long) (task_io_service_operation.hpp:37)
by 0x4236AD: 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:412)
by 0x423302: boost::asio::detail::task_io_service::run(boost::system::error_code&) (task_io_service.ipp:153)
by 0x42393A: boost::asio::io_service::run() (io_service.ipp:59)
by 0x42EB34: boost::_mfi::mf0<unsigned long, boost::asio::io_service>::operator()(boost::asio::io_service*) const (mem_fn_template.hpp:49)
by 0x42EA72: unsigned long boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> >::operator()<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list0>(boost::_bi::type<unsigned long>, boost::_mfi::mf0<unsigned long, boost::asio::io_service>&, boost::_bi::list0&, long) (bind.hpp:243)
by 0x42E91E: boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > >::operator()() (bind_template.hpp:20)
followed by a later acquisition of lock at 0x64C720
at 0x4C2C692: pthread_mutex_lock (hg_intercepts.c:495)
by 0x408845: boost::asio::detail::posix_static_mutex::lock() (posix_static_mutex.hpp:44)
by 0x40E523: boost::asio::detail::scoped_lock<boost::asio::detail::posix_static_mutex>::scoped_lock(boost::asio::detail::posix_static_mutex&) (scoped_lock.hpp:36)
by 0x424EE7: boost::asio::detail::signal_set_service::deliver_signal(int) (signal_set_service.ipp:431)
by 0x42477C: boost::asio::detail::signal_set_service::pipe_read_op::do_perform(boost::asio::detail::reactor_op*) (signal_set_service.ipp:95)
by 0x409DE0: boost::asio::detail::reactor_op::perform() (reactor_op.hpp:40)
by 0x422C2F: boost::asio::detail::epoll_reactor::descriptor_state::perform_io(unsigned int) (epoll_reactor.ipp:622)
by 0x422D38: boost::asio::detail::epoll_reactor::descriptor_state::do_complete(boost::asio::detail::task_io_service*, boost::asio::detail::task_io_service_operation*, boost::system::error_code const&, unsigned long) (epoll_reactor.ipp:648)
by 0x409C69: boost::asio::detail::task_io_service_operation::complete(boost::asio::detail::task_io_service&, boost::system::error_code const&, unsigned long) (task_io_service_operation.hpp:37)
by 0x4236AD: 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:412)
by 0x423302: boost::asio::detail::task_io_service::run(boost::system::error_code&) (task_io_service.ipp:153)
by 0x42393A: boost::asio::io_service::run() (io_service.ipp:59)
【问题讨论】:
您是在问,hellgrind 报告的数据竞争是否是线程库中的错误?我对此表示怀疑,更可能是 valgrind 的误报。 是的,这可能是线程库中的错误。该日志不仅包含数据竞争,还包含错误的锁定顺序。我知道,valgrind 可能会给出误报。为了确定,我发布了一个问题。 Sam,我想问你,你用什么来测试你的应用程序? 【参考方案1】:HTTP Server 3 example 使用线程池。虽然 Valgrind 是一套非常有用的程序,但正确使用它需要一点技巧。作为 helgrind documentation states,最好在项目的早期就开始使用 helgrind。根据我的经验,在 hlgrind 上抛出一个现有的多线程程序很可能会报告许多误报。例如,使用 posix 条件变量时 helgrind 不能总是检测到数据竞争,这句话来自我之前链接的 helgrind 文档
避免使用 POSIX 条件变量。如果可以,请使用 POSIX 信号量 (sem_t, sem_post, sem_wait) 做线程间事件信号。 初始值为零的信号量特别适用于 这个。
这可能是您引用的误报的原因。 Asio 和 Thread 库都使用条件变量作为其实现的一部分。我非常怀疑可能的数据竞争或不正确的锁定顺序是由于任一库中的错误造成的。值得在这里引用Jeff Atwood's First Rule of Programming
成为一个谦逊的程序员的一个重要部分是意识到 每当您编写的代码出现问题时,总是 你的错。操作系统、编译器、 或第三方产品——但这不应该是您的第一个想法。 该错误更有可能存在于应用程序代码中 正在开发中。
【讨论】:
以上是关于boost asio HTTP Server 3 示例或 boost 错误中是不是存在错误?的主要内容,如果未能解决你的问题,请参考以下文章
在 C++11 中对 boost::asio 套接字对象重复 std::move
boost asio one client one thread