这两者有什么区别吗?还是我的安全,以取代所有出现boost::bind的std::bind在我的代码,从而消除对加速的依赖?
我想要的是当一个消息队列接收到一个 int N 时,处理函数将在 N 秒后被调用。下面是我的代码。
如果两个近消息队列的持续时间秒数大于 int N,则运行正常,但是当两个接收到的消息队列之间的持续时间秒数小于 N 时,处理程序将在一个处理程序中打印“操作已取消”,这不是我想要的想。
如果您有任何帮助,我将不胜感激。
#include <boost/asio.hpp>
#include <zmq.h>
#include <boost/thread.hpp>
#include <iostream>
boost::asio::io_service io_service;
void* context = zmq_ctx_new();
void* sock_pull = zmq_socket(context, ZMQ_PULL);
void handler(const boost::system::error_code &ec) {
std::cout << "hello, world" << "\t" << ec.message() << std::endl;
}
void run() {
io_service.run();
}
void thread_listener() {
int nRecv;
boost::asio::deadline_timer timer(io_service, boost::posix_time::seconds(0));
while( true ) {
zmq_recv(sock_pull, &nRecv, sizeof(nRecv), 0);
std::cout << nRecv << std::endl;
timer.expires_from_now(boost::posix_time::seconds(nRecv));
timer.async_wait(handler);
}
}
int main(int argc, …Run Code Online (Sandbox Code Playgroud)