On Thu, Jul 5, 2012 at 3:27 AM, Ivan Pechorin <[email protected]>wrote:
> > > 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." > My bad, I only checked the guide/man-pages and was a little unsure that a mutex would do the trick. > 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. > That's the case, I was ok with the performance penalty of creating/closing the socket, but the file descriptor limit is a problem. The mutex lock/unlock will not be an issue. Thanks a lot, Thiago
_______________________________________________ zeromq-dev mailing list [email protected] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
