[zeromq-dev] Want to use ZMQ socket in multithreading

Auer, Jens jens.auer at cgi.com
Fri Jul 29 10:47:19 CEST 2016


Hi Bharat,

ZeroMQ is not rhead-safe and sockets shall not be used concurrently from different threads. I think there are some new socket types in the master branch which are thread-safe, but this not part of the release version. As they are not thread-safe, you cannot reliably check conditions on them when using them concurrently. You could use a mutex to prevent concurrent access.

The recommended alternative would be to have independent theads that do not share data or resources communicating via ZMQ_PAIR sockets. I would strongly recommend to go that route as data-sharing multi-threading is a highway to hell. It does also often not offer the performance/scalability gain that you are hoping for because of congestion at the shared resources.

Cheers,
  Jens

--
Jens Auer | CGI | Software-Engineer
CGI (Germany) GmbH & Co. KG
Rheinstraße 95 | 64295 Darmstadt | Germany
T: +49 6151 36860 154
jens.auer at cgi.com<mailto:jens.auer at cgi.com>
Unsere Pflichtangaben gemäß § 35a GmbHG / §§ 161, 125a HGB finden Sie unter de.cgi.com/pflichtangaben<http://de.cgi.com/pflichtangaben>.

CONFIDENTIALITY NOTICE: Proprietary/Confidential information belonging to CGI Group Inc. and its affiliates may be contained in this message. If you are not a recipient indicated or intended in this message (or responsible for delivery of this message to such person), or you think for any reason that this message may have been addressed to you in error, you may not use or copy or deliver this message to anyone else. In such case, you should destroy this message and are asked to notify the sender by reply e-mail.
________________________________
Von: zeromq-dev [zeromq-dev-bounces at lists.zeromq.org]" im Auftrag von "Bharat Somani [bharatdsomani at gmail.com]
Gesendet: Freitag, 29. Juli 2016 09:09
An: ZeroMQ development list
Betreff: [zeromq-dev] Want to use ZMQ socket in multithreading

Hi All,

I am creating socket in one thread and sharing this to be used in multiple threads. But when I try to use it, sometimes I get error

Assertion failed: check () (src/msg.cpp:248)

I was breaking ZMQ's rule of sharing sockets among threads.

Is there any way to know whether the socket is currently in used (sending data) state? If there is a way, I can check it before sending the data.


Regards,
Bharat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20160729/347e7e39/attachment.htm>


More information about the zeromq-dev mailing list