[zeromq-dev] Thread Safe sockets
Gary Wright
at2002+zmq at me.com
Mon Feb 6 22:08:52 CET 2012
On Feb 6, 2012, at 3:45 PM, Martin Sustrik wrote:
> Hi Nadav,
>
>> I like the concept of having thread-safe sockets, but it seems that this
>> implementation does not really deliver what a user would expect from a
>> thread-safe socket. For instance, if two threads try to
>> receive simultaneously from the same socket, each of them might obtain
>> different frames that belong to one multipart message. Similarly,
>> sending messages simultaneously from different threads over the same
>> socket will get the individual frames intertwined.
>
> That's a pretty good argument. The only question is whether it's an
> argument against thread-safe sockets or an arguments against multi-part
> messages :)
>
> What makes the problem bad is the fact that there may be arbitrary
> interval between sending/receiving 1st and 2nd part of the message.
> During that time the socket has to be locked which in turn means that
> all other threads accessing it will be blocked for the period (1 hour,
> for example).
You could avoid the indefinitely locking and still have multi-part messages
by changing the API such that all message parts have to be handed to/from
the API in one call.
At first I thought the multi-part message system would be great for
streaming chunks of data but each message is buffered within ZMQ
before being delivered via the API so any sort of streaming
is going to have to be done via multiple messages anyway. (Someone
correct me if I'm misunderstanding anything).
Gary Wright
More information about the zeromq-dev
mailing list