[zeromq-dev] Sharing socket safely between threads
Bill Torpey
wallstprog at gmail.com
Mon May 7 17:34:10 CEST 2018
If you’re thinking of using inproc sockets for inter-thread signaling, you may find this helpful: https://github.com/WallStProg/zmqtests/tree/master/threads <https://github.com/WallStProg/zmqtests/tree/master/threads>
I put this together to illustrate the problems discussed here: https://github.com/zeromq/libzmq/issues/2759 <https://github.com/zeromq/libzmq/issues/2759>
> On May 7, 2018, at 11:26 AM, Mark Botner <mbotner at gmail.com> wrote:
>
> I've shared a zmq socket between threads and protected it with Mutex and it works just fine. I've also used the "inproc" transport to allow threads to communicate with each other and relay messages to a socket that isn't shared between threads.
>
>
> Mark
>
> On Mon, May 7, 2018 at 8:42 AM, Attila Magyari <atti86 at gmail.com <mailto:atti86 at gmail.com>> wrote:
> Hello,
>
> I know that zmq sockets are not thread safe. However I can't think of a good design (explained below) without using the socket in several threads. What I want to do is connect the socket in a thread, and then use it in a different one until the end, and never in parallel between several threads. I will guard the access with a mutex as well. Do you think this will be safe?
>
> Just in case someone might have a better idea for my design, here is what I'm trying to do:
> I have an application which starts another process, passes a port to the newly created process, so it can connect back to the main application through a ZMQ_PAIR socket. Both processes are local to the machine. The main application will request from the second one, but the second one can initiate messages without an explicit request as well. Do you have a nicer design to achieve something like this?
>
> Thank you in advance!
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org <mailto:zeromq-dev at lists.zeromq.org>
> https://lists.zeromq.org/mailman/listinfo/zeromq-dev <https://lists.zeromq.org/mailman/listinfo/zeromq-dev>
>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> https://lists.zeromq.org/mailman/listinfo/zeromq-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20180507/e7faead1/attachment.htm>
More information about the zeromq-dev
mailing list