1

Is it safe to access a NetMQ socket from multiple threads, as long as they are not using it simultaneously?

For example,
is the following scenario OK:

  1. Thread A uses a socket.
  2. Thread A ends.
  3. Thread B uses the same socket.

If not,
must the sole operating thread be the very same who created the socket?

user3666197
  • 1
  • 6
  • 50
  • 92
tearvisus
  • 2,013
  • 2
  • 15
  • 32

1 Answers1

3

Technically you can. However how can you guarantee that it is actually not used concurrently? I suggest using a lock if you want to use the socket from multiple threads. Also take a look at NetMQQueue, is new and not documented, thread safe for enqueueing only. It might help you solve synchronization threads between NetMQ Sockets as you can poll on it with the Poller.

https://github.com/zeromq/netmq/blob/master/src/NetMQ.Tests/NetMQQueueTests.cs

somdoron
  • 4,653
  • 2
  • 16
  • 24
  • Actually, I can guarantee it easily with Reactive Extensions which I use a lot in my project. Furthermore, I don't need locks to do it. – tearvisus Dec 11 '15 at 16:13