public void destroy_socket(SocketBase socket_) {
        slot_sync.lock ();

        int tid;
        //  Free the associated thread slot.
        try {
            tid = socket_.get_tid ();
            empty_slots.add (tid);
            slots [tid].close();
            slots [tid] = null;
    
            //  Remove the socket from the list of sockets.
            sockets.remove (socket_);
    
            //  If zmq_term() was already called and there are no more socket
            //  we can ask reaper thread to terminate.
            if (terminating && sockets.isEmpty ())
                reaper.stop ();
        } finally {
            slot_sync.unlock ();
        }
    }