tearvisus
tearvisus

Reputation: 2033

Accessing NetMQ sockets from multiple threads

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?

Upvotes: 1

Views: 1143

Answers (1)

somdoron
somdoron

Reputation: 4842

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

Upvotes: 3

Related Questions