[zeromq-dev] Thread-safe sockets (cont.)

Chuck Remes cremes.devlist at mac.com
Thu Feb 16 23:05:17 CET 2012


On Feb 16, 2012, at 3:51 PM, Pieter Hintjens wrote:

> Hi,
> 
> Does anyone have a valid use case for thread-safe sockets? It seems
> that the semantics are fuzzy and using this would lead to poor design.
> What happens if two threads are polling the same sockets, but one
> message arrives?

zmq_poll() would probably need to be modified to disallow multiple threads from polling. Alternately, zmq_poll() would need to disallow a poll_item list that contained a socket that is already a member of another call to zmq_poll() from another thread.

Ugly. Error prone. I don't see how this could work well without some hacks. And now "thread safety" would generate a shit-ton of additional questions about why zmq_poll() was so strict, broken, etc.

> What if two threads are in a blocking recv on the
> same socket?

Only one thread would be allowed through the mutex to block on the receive. The second thread would block on the mutex. No problem.

> If we don't have a clear problem that this change is fixing, I'd like
> to patch it out.

I don't have a use-case but I think there are at least 2 people on the list who do. I hope they speak up.

cr





More information about the zeromq-dev mailing list