[zeromq-dev] Exiting a child thread

Luca Boccassi luca.boccassi at gmail.com
Wed Apr 18 00:14:28 CEST 2018


On Tue, 2018-04-17 at 13:10 +0000, Cerizza, Giordano wrote:
> Hi,
> I have the following problem: I have a source of messages connected
> to a proxy; the PULL/PUSH proxy reroutes the
> messages via inproc to a multithreaded service that receives the
> messages and pushes them to a destination sink.
> Here some pseudocode to help understand the streaming class:
> 
> void main(){
> // definition of context (ctx_) and sockets for PULL/PUSH proxy
> (frontend,backend)
> (...)
> pthread worker[N]
> for loop for number of thread
>    pthread_create(&worker[i], NULL, worker_task, (void*)ctx_)
> try{
>    zmq::proxy (*frontend, *backend, NULL);
> } catch(...){
>   // stuff
> }
> }
> 
> void* worker_task(void *arg){
> zmq::context_t *context = (zmq::context_t*) arg;
> // definition of the sockets to pull from (socket_from) and push to
> (socket_to)
> (...)
> // operations on messages (receive and send)
> (...)
> // exiting the worker_task
> pthead_exit(NULL);
> }
> 
> Observations: my system hangs before exiting the child thread. I
> tried to close the sockets (zmq_close) and destruct (zmq_term) the
> context for the child but nothing happens. How do I safely leave the
> thread and move on with my code i.e. close the sockets and destroy
> the context for the proxy, destruct the streaming class, and move to
> operate on the message sink?
> 
> Thanks in advance
> Best wishes

Do not destroy the context, it's global.
Just close the socket.

-- 
Kind regards,
Luca Boccassi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: This is a digitally signed message part
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20180417/063348ee/attachment.sig>


More information about the zeromq-dev mailing list