2

My program uses ZMQ for communication. Namely, a server (C++, linux) creates an XPUB socket and then in one thread reads it, and in another one publishes data (writes).

The client (java, jzmq, linux) create a SUB socket, and subscribes using it.

After some time, the server side receives SIGABRT in the reading thread.

What may be a source of problem? Read/Write in different threads or creating XPUB/SUB pair?

In case the problem is in multi threading, what is a right paradigm to use XPUB socket?

Jay Kominek
  • 8,674
  • 1
  • 34
  • 51
  • StackOverflow encourages to formulate high-quality questions by a convention of MCVE-code, that demonstrates the problem asked about. Not doing so leaves other just a change to guess. Feel free to update the post with such MCVE-code. ZeroMQ is great in building both a distributed ( non-shared ), and smart-shared ( central ) Context()-instance fabricated socket Scalable Formal Communication Archetype-rich signalling / messaging layers, but **asking what caused `SIGABRT` in some of my code deployment** is suited more for a Clairvoyance-site, than for a StackOverflow Community of Knowledge, ok? – user3666197 Sep 07 '17 at 15:44

1 Answers1

6

https://zguide.zeromq.org/docs/chapter2/#Multithreading-with-ZeroMQ

Don’t share ZeroMQ sockets between threads. ZeroMQ sockets are not threadsafe. Technically it’s possible to migrate a socket from one thread to another but it demands skill. The only place where it’s remotely sane to share sockets between threads are in language bindings that need to do magic like garbage collection on sockets.

Will S
  • 744
  • 8
  • 17
bobah
  • 18,364
  • 2
  • 37
  • 70
  • Probably answer referred to [this link](http://wiki.zeromq.org/blog:multithreading-magic#toc6) – Shubham May 03 '21 at 12:41
  • Yeah, that's why link-only answers are not so great. Link in the answer is dead, and link in the comment is about solution implemented in zmq libs, not about how to write multithreaded application using it. Currently I am facing similar problem: each socket lives in it's own thread (they are not shared), they use the same context (supposed to be thread safe), and with enough load in the systems I have collisions and corrupted msgs. – pptaszni Sep 20 '22 at 14:44