cppzmq icon indicating copy to clipboard operation
cppzmq copied to clipboard

Monitor in separate thread doesn't terminate on abort() call

Open CMun opened this issue 8 years ago • 3 comments

Hello,

due to changes of zmq.hpp from 4.2.1 to 4.2.2, calling abort on a monitor object running in a separate thread doesn't end the monitor taks.

The problem is, that monitor loops unconditionally and doesn't check the check_event return value:

void monitor(socket_t &socket, const char *addr_, int events = ZMQ_EVENT_ALL)
{
  init (socket, addr_, events) ;
  while(true)
  {
    check_event(-1) ;
   }
}

Furhter on, within check_event, ETERM is not necessarily set, so you might get an violated assertion there.

Is this intended? Alternatively, what is the recommended way of terminating an monitor object in a separate thread on program end?

CMun avatar Feb 22 '18 14:02 CMun

Hi all, Is there progress with this issue?

definename avatar Jul 27 '18 16:07 definename

顺序问题,在Linux上顺序应该 socket.close; context.close; monitor thread end(monitor_t will throw an exception)

Bates0000 avatar Sep 23 '22 02:09 Bates0000

No this has not been fixed. The best way is probably not call that constructor and write you own run function for now (until someone writes a pull request).

monitor_t mon;
mon.init(socket, addr, events);
while (true) {
    if (!mon.check_event(-1) && zmq_errno() == ETERM) // or something else
        break;
}

gummif avatar Sep 23 '22 09:09 gummif