Hi Joe, there is a big mistake in the check_interrupt logic, because you call zstr_recv *twice*. One time in main actor, the second time in the function. See the changes I did to make your example working
--- t.c.orig 2018-03-09 10:04:31.685006467 +0100 +++ t.c 2018-03-09 10:13:55.594123894 +0100 @@ -2,14 +2,12 @@ #include <iostream> #include <string.h> -int check_interrupt(zsock_t *pipe) { +int check_interrupt(const char *msg) { int interrupt = 0; - char *msg = zstr_recv(pipe); - if (zsys_interrupted || (msg && !strcmp(msg, "$TERM"))) + if (zsys_interrupted || (msg && streq(msg, "$TERM"))) interrupt = -1; - free(msg); return interrupt; } @@ -28,9 +26,9 @@ while(1) { char *str = zstr_recv(pipe); std::cout << "timer_thread received: " << str << std::endl; - free(str); - if (check_interrupt(pipe)) + if (check_interrupt(str)) break; + free(str); // request list from socket_thread zstr_send(args, "list request"); // recv list and do stuff @@ -57,9 +55,9 @@ while(1) { char *str = zstr_recv(pipe); std::cout << "socket_thread: received: " << str << std::endl; - free(str); - if (check_interrupt(pipe)) + if (check_interrupt(str)) break; + free(str); // Parse the msg, either add msg to list or return list } } @@ -97,5 +95,4 @@ zactor_destroy(&timer_zactor); zsock_destroy(&a_zsock); zloop_destroy(&loop); - assert (loop == NULL); } A few recommendations to make your future experiments easier. 1. Always write start/stop test for your actors. The first thing I did was that I commented out most of your main to see if actor can be created and destroyed. Then it was easy to spot the mistake. 2. Use modern C - there is no point of writing functions returning 0 and -1, there is bool type and -Wc++-compat helping you to avoid C++ compilers incompatibility 3. There is zstr_free function in czmq, use it and you won’t suffer from double free errors any more 4. Learn zproject later on - see https://hintjens.gitbooks.io/scalable-c/content/chapter3.html - it's great way to generate great C and C++ projects including way to write unit tests, run them and more and more. On Thu, Mar 8, 2018 at 6:24 PM, Georger, Joseph < joseph.geor...@stresearch.com> wrote: > Okay, here is a simplified example that exhibits the behavior. I realize > this may end up being simply how to properly terminate threads, but I want > to make sure I don't miss anything in the czmq/zloop context.... > > https://pastebin.com/MsjDH6k8 > > Thanks, > Joe > > > ------------------------------ > > Message: 2 > Date: Thu, 8 Mar 2018 10:38:34 +0100 > From: Michal Vyskocil <michal.vysko...@gmail.com> > To: ZeroMQ development list <zeromq-dev@lists.zeromq.org> > Subject: Re: [zeromq-dev] czmq zloop proper shut down of zactors > Message-ID: > <CAJp4ekvmyRQX+bNVEn9Qx1DdsvH+tKYtu-i9vZTRR1m8enStnw@mail. > gmail.com> > Content-Type: text/plain; charset="utf-8" > > Hi Joe, > > can you post minimal reproducer somewhere? I tried to spot the > problem, but > without having working example it's hard. > > Bye > Michal > > > _______________________________________________ > zeromq-dev mailing list > zeromq-dev@lists.zeromq.org > https://lists.zeromq.org/mailman/listinfo/zeromq-dev > -- best regards Michal Vyskocil
_______________________________________________ zeromq-dev mailing list zeromq-dev@lists.zeromq.org https://lists.zeromq.org/mailman/listinfo/zeromq-dev