[zeromq-dev] Thread Safe sockets

john skaller skaller at users.sourceforge.net
Tue Feb 7 14:55:51 CET 2012

On 07/02/2012, at 8:41 PM, Nadav Samet wrote:

> How readable is that? And what about the global variables? etc.
> I absolutely agree that recv() is more readable than using callbacks, but it has the undesirable characteristic that it blocks the calling thread until the response arrives...

That's not undesirable , its the same as for a callback: the callback "stops running in between
messages" just the same.

>  Imagine an RPC server A with a few worker threads that in order to process a request from a client it needs to make a request to another server B. Having a worker thread on server A blocking on recv() from a socket that is connected to server B will hurt performance. The waiting thread could have been serving other requests while it has been waiting inside recv().

This is true, but only because OS threads are heavyweight: context switches are slow
and they eat up a lot of resources.

Fibres (as used in Felix, Erlang, MLton, Haskell I believe, and also Windows) are
much more lightweight.

john skaller
skaller at users.sourceforge.net

More information about the zeromq-dev mailing list