是否希望 boost asio timer 阻止“取消”?

Is boost asio timer expected to block on `cancel`?

我观察到 boost::asio::steady_timer 在调用 cancel 时阻塞并且 async_wait 提供的回调已经在执行。这是预期的行为吗?它是可配置的吗?为什么首先它必须阻止?

调用堆栈:

#0  __lll_lock_wait () at ../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:135
#1  0x00007f4d4c703dbd in __GI___pthread_mutex_lock (mutex=0x20000616f558) at ../nptl/pthread_mutex_lock.c:80
#2  0x000070000086ef75 in boost::asio::detail::posix_mutex::lock (this=0x20000616f558) at /source/boost/include/boost/asio/detail/posix_mutex.hpp:52
#3  0x000070000087036e in boost::asio::detail::conditionally_enabled_mutex::scoped_lock::scoped_lock (this=0x40000623e970, m=...) at /source/boost/include/boost/asio/detail/conditionally_enabled_mutex.hpp:55
#4  0x00007000009ebf7f in boost::asio::detail::epoll_reactor::cancel_timer<boost::asio::detail::chrono_time_traits<std::chrono::_V2::steady_clock, boost::asio::wait_traits<std::chrono::_V2::steady_clock> > > (this=0x20000616f520, queue=..., timer=..., 
    max_cancelled=18446744073709551615) at /source/boost/include/boost/asio/detail/impl/epoll_reactor.hpp:62
#5  0x00007000009e8322 in boost::asio::detail::deadline_timer_service<boost::asio::detail::chrono_time_traits<std::chrono::_V2::steady_clock, boost::asio::wait_traits<std::chrono::_V2::steady_clock> > >::cancel (this=0x200006188f60, impl=..., ec=...)
    at /source/boost/include/boost/asio/detail/deadline_timer_service.hpp:144
#6  0x00007000009e5211 in boost::asio::basic_waitable_timer<std::chrono::_V2::steady_clock, boost::asio::wait_traits<std::chrono::_V2::steady_clock> >::cancel (this=0x20009470cfc8)
    at /source/boost/include/boost/asio/basic_waitable_timer.hpp:329

看起来问题是由于我们在多进程环境中工作。所有进程共享相同的内存,在这个共享内存上创建的所有对象,包括互斥量、线程等。为了在这种情况下正常运行,系统中使用的互斥量是使用 PTHREAD_PROCESS_SHARED 属性创建的。显然,asio 互斥锁不是用这样的属性创建的,所以我猜这是互斥锁卡在意外位置的问题。一旦 io_contextsteady_timer 开始只在一个进程中执行,它就开始按预期工作