[zeromq-dev] non-clean exit - "Context was terminated"

Chris Laws clawsicus at gmail.com
Mon Sep 2 05:19:49 CEST 2013

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 <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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130902/babfd643/attachment.htm>

More information about the zeromq-dev mailing list