implementation of 'socket_stop' function

this function can be called from any thread, and will wait for each of
them to join the thread which calls ‘socket_listen’