为什么多次调用ZMQ Context的析构函数?
inline zmq::context_t ctx_proxy(1);
class MyClass {
private:
// data connections
zmq::socket_t* sock_frontend;
zmq::socket_t* sock_backend;
// utils
std::thread* t = nullptr;
public:
MyClass() {
init();
connect();
}
void init() noexcept {
sock_frontend = new zmq::socket_t(ctx_proxy, zmq::socket_type::router);
sock_backend = new zmq::socket_t(ctx_proxy, zmq::socket_type::dealer);
}
void connect() {
sock_frontend->bind("tcp://127.0.0.1:8880");
sock_backend->bind("tcp://127.0.0.1:8888");
t = new std::thread(&MyClass::proxy, this);
std::cout << "Thread-ID: " << t->native_handle() << std::endl;
}
void proxy() {
zmq::proxy(static_cast<zmq::socket_ref>(*sock_frontend),
static_cast<zmq::socket_ref>(*sock_backend));
}
};
int main() {
MyClass();
}
当我运行它时,它显示此错误:
Thread-ID: 139944261580544
terminate called after throwing an instance of 'zmq::error_t'
what(): Context was terminated
Aborted (core dumped)