2012/7/5 Thiago Cangussu <[email protected]> > > The question is: what should I do to make this multi-threaded usage of > sockets safe? Is it enough to guarantee that multiple threads do not > perform send/receive simultaneously? > > This is already in the FAQ [1]:
"For those situations where a dedicated socket per thread is infeasible, a socket may be shared *if and only if *each thread executes a full memory barrier before accessing the socket. Most languages support a Mutex or Spinlock which will execute the full memory barrier on your behalf." In particular, for Linux/UNIX systems with pthreads, the memory barrier by pthread_mutex_lock(), pthread_mutex_unlock() and a bunch of other pthread_* functions is guaranteed by the POSIX specification [2]. So, if you don't have control on a number of threads that use ZeroMQ sockets and the performance penalty of mutex lock/unlock on every operation is not a problem for your needs, just make sure that your pool of sockets is protected by mutexes. [1] http://www.zeromq.org/area:faq [2] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_11
_______________________________________________ zeromq-dev mailing list [email protected] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
