[zeromq-dev] zactor destroy sequence
Arnaud Loonstra
arnaud at sphaero.org
Sun Nov 2 13:11:41 CET 2014
Then am I correct that the echo_actor example is not signaling the pipe
on exit while it should like this?
static void
echo_actor (zsock_t *pipe, void *args)
{
// Do some initialization
assert (streq ((char *) args, "Hello, World"));
zsock_signal (pipe, 0);
bool terminated = false;
while (!terminated) {
zmsg_t *msg = zmsg_recv (pipe);
if (!msg)
break; // Interrupted
char *command = zmsg_popstr (msg);
// All actors must handle $TERM in this way
if (streq (command, "$TERM"))
terminated = true;
else
// This is an example command for our test actor
if (streq (command, "ECHO"))
zmsg_send (&msg, pipe);
else {
puts ("E: invalid message to actor");
assert (false);
}
free (command);
zmsg_destroy (&msg);
}
+ // send signal to actor to confirm exit
+ zsock_signal (pipe, 0);
}
On 11/02/2014 12:41 PM, Pieter Hintjens wrote:
> If you send and wait without a timeout, it happens that the actor
> thread is gone, and its pair socket destroyed, before you get here.
> Then the calling thread blocks waiting for a reply that never arrives.
>
> The return signalling is done by the zactor wrapper, not the actor
> itself. This isn't entirely symmetrical, that's true.
>
> On Sat, Nov 1, 2014 at 10:18 PM, Arnaud Loonstra <arnaud at sphaero.org> wrote:
>> Hi all,
>>
>> I'm going through the zactor class to understand it better. I'm slightly
>> confused by the destroy sequence:
>>
>> At line 182 of zactor.c:
>> // Signal the actor to end and wait for the thread exit code
>> // If the pipe isn't connected any longer, assume child thread
>> // has already quit due to other reasons and don't collect the
>> // exit signal.
>> zsock_set_sndtimeo (self->pipe, 0);
>> if (zstr_send (self->pipe, "$TERM") == 0)
>> zsock_wait (self->pipe);
>> zsock_destroy (&self->pipe);
>>
>> So when destroy is called the actor method will receive the $TERM
>> command. The destroy sequence waits for a signal from the actor command.
>>
>> But why the == 0. Doesn't that mean that the zstr_send send 0 bytes thus
>> failed sending?
>>
>> Then the echo_actor example just sets: (line 268)
>> terminated = true;
>> It nevers signals back.
>>
>> It does work that's why I'm confused about what's happening.
>> Can anybody turn the light on? :)
>>
>> Rg,
>>
>> Arnaud
>> --
>> w: http://www.sphaero.org
>> t: http://twitter.com/sphaero
>> g: http://github.com/sphaero
>> i: freenode: sphaero_z25
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev at lists.zeromq.org
>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
--
w: http://www.sphaero.org
t: http://twitter.com/sphaero
g: http://github.com/sphaero
i: freenode: sphaero_z25
More information about the zeromq-dev
mailing list