简体   繁体   中英

How to remove a blocking recv without a zmq_term tha kills the central zmq_context?

I have several threads attached to the same zmq_context on a thread.

The recommended way to close is to use zmq_term which will wake up the thread but that will close all sockets.

I have different sockets on different threads and wish to share the same context (to reduce zmq thread count).

There is a recv which blocks and I would like to be able to shut it down immediately without affecting all the other sockets.

Is this even possible with zmq ?

Going a multithreading way while using a blocking step is oxymoron per se

Redesign your reading operations so as to avoid blocking recv s or add another signalling layer to allow another thread to kill those hanging upon not receiving aKeepAliveSIG from their regular operations. Many options to extend this rather primitive mock-up.

ZeroMQ is a very good toolkit at this.

在此处输入图片说明 This would work for a case, where [Worker] units do not remain hanging in a blocking .recv()

As written earlier above, an external thread can shoot and remove a process, that is dead ( not responding, so also not reading any soft-signalling ) simply by having lost a few regular softKeepAliveSIG update messages from [Worker] , thus assuming it was lost ( ... which functionality the Fig. 19, from a great book "Code Connected, Volume 1", cannot itself do on any dead- [Worker] )

If you want to kill the thread with the blocking recv, one way is to arrange for some other 'controller' thread to send it a 'kill' message. The kill message is just an ordinary message, but the protocol around it will result in the receiving thread tidying up and exiting.

There are plenty of examples, but search for "Parallel Pipeline with Kill Signaling" in the current zmq guide .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM