[zeromq-dev] connect from a different thread
Gaspard Bucher
gaspard at teti.ch
Sun Jan 2 12:52:01 CET 2011
I installed 2.1 and things look better.
Instead of using zmq_poll on two socket, I will try to subscribe to the
inproc and manually detect "connect" messages.
Thanks for the feedback.
Gaspard
On Sun, Jan 2, 2011 at 12:42 PM, Martin Sustrik <sustrik at 250bpm.com> wrote:
> Hi Gaspard,
>
>
> I have a zmq.SUB socket handling remote messages in thread A. It spends
>> most of its time in recv().
>>
>> Some other thread B running mDNS finds services and I want it to connect
>> the subscriber (created in thread A) to the remote end.
>>
>> Is it ok to connect from a different thread ?
>>
>
> No. You cannot access one socket from multiple threads. In 2.1 you can
> migrate a socket to another thread, however, you still can't access it from
> multiple threads in parallel.
>
>
>> Is it ok to connect while the socket is in recv() ?
>>
>
> No. As explained above, a socket is not thread-safe.
>
>
> If not, one solution I see would be to connect the subscriber to an ipc
>> socket (created in the mDNS loop) to receive connection info. Is this
>> the way to handle such a pattern ?
>>
>
> Yes. You can create another socket to pass connection info's to the
> subscriber thread. The subscriber thread then has to wait using zmq_poll,
> polling on both sockets, instead of simply calling recv.
>
> HTH
> Martin
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20110102/e1ead3dc/attachment.htm>
More information about the zeromq-dev
mailing list