After more investigation it appears that the problem I am seeing is associated with the thread code sitting blocked in recv until the main thread performs the context shutdown. When the thread begins shutting down it goes through the termination sequence of events, one of which is to set the linger option on sockets. I think it is this action which triggers the "Context was terminated" to be emitted to stdout.
I modified the simple example to send a message, from main to the thread, upon detecting zctx_interrupted. This kicks the thread out of the blocking recv call sooner, allowing it to exit the while loop and begin shutting down. However, I found I still needed to insert a wait, allowing the thread to finish up, before shutting down the context to avoid triggering the"Context was terminated" error. The period of time I wait for the thread to shut down is a guess. Having a feature like thread join might resolve what appears to be a race condition here. Here <https://gist.github.com/claws/6394946#file-threads-example-fixed-c>is a modified version of the simple example that appears to work - it no longer raises the "Context was terminated" error to stdout on shutdown.
_______________________________________________ zeromq-dev mailing list [email protected] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
