The idea is to solve to problem by
- preceding the listener methods invocation by IsListening check and
- enforcing the sequence by rwLock
The problem is, however, that the stopping thread will be blocking while shuts down. This prevents scenario: send "terminate" signals to all running processes and wait for them to finish. The only alternatives I see to enable the concurrent shut down: 1) go back to single thread, which accepts two messages: 'stop' and 'new connection' to be processed in a new thread; or 2) create a terminator thread for every server.