[zeromq-dev] Socket use from several threads

Chuck Remes lists at chuckremes.com
Tue Jul 17 16:26:51 CEST 2012


On Jul 17, 2012, at 9:14 AM, moteus wrote:

> Chuck Remes <lists <at> chuckremes.com> writes:
> 
>> You should create only ONE context. The context can be passed to each thread;
> any socket you create in a
>> thread should only be used from that thread.
>> 
>> I recommend that you read the guide and the FAQ. These ideas are discussed in
> both places.
>> 
>> cr
>> 
> 
> I don't like to create a socket only for one request.
> (connect=>send/recv=>close)
> But as I understood there is no other way.
> About context - sorry for a silly question :)

Oh, so the threads are short-lived then. In that case, you should create a pool of them and have each thread "check out" the socket from the pool when it needs to use it and check it back in again when the thread exits. If the pool is protected by a mechanism (like a mutex) that employs a full memory barrier, then it will be safe.

cr




More information about the zeromq-dev mailing list