Hi Martin, On Mon, Feb 4, 2013 at 9:35 AM, Martin Sustrik <sustrik@xxxxxxxxxx> wrote: > Hi all, > > I would like to do yet one more API change before it's too late and API is > cast in stone. > > The idea is to remove nn_init() and nn_term() functions altogether. The > library would be initialised when first socket is created and terminated > when the last socket is closed. > > Considerations: > > First, nn_close() would have to be synchronous, ie. wait for the pending > outbound data to be sent or for linger interval to expire. This is done in > current codebase anyway (and it simplifies the code a lot), however, it's > not consistent with how 0MQ behaves. > > Second, ETERM functionality which is useful for shutting down multi-threaded > applications would have to behave a bit differently. My proposal would be to > re-purpose the nn_term() function to be an optional way of saying "make any > subsequent call to nanomsg library, except for nn_close(), fail with ETERM). > If it is not called, it's up to the user to notify all the threads about the > shutdown. After all, if there's only one thread in the application, there's > no need for such notification anyway. > > Thoughts? > I find the following two situations subtle: 1. It is unsafe to create two sockets in two different threads, unless you already created at least one socket. Am I right? 2. When you close and reopen socket, sometimes worker threads are shut down and started again. Sometimes not. Closing and opening sockets is useful for some applications. While I don't have good use cases that closes sockets many times per second, I might be not very creative :) -- Paul