def start_handler_thread
    @session_mutex = Mutex.new
    @thread_mutex = Mutex.new.lock
    @thread = Thread.start do
      cur_thr = Thread.current
      THREAD_GROUP.add cur_thr
      cur_thr[:session] = self
      cur_thr[:in_handler_thread] = true
      cur_thr.abort_on_exception = true
      begin
        loop do
          @thread_mutex.synchronize do
            cur_thr[:return] = cur_thr[:block].call
            cur_thr[:response_done].unlock
          end
          @thread_mutex.lock
        end
      rescue Exception => err
        err_str = %^Exception in #{cur_thr.inspect}:\n#{err}\n#{err.backtrace.join("\n")}\n!!^
        puts err_str
        
        
        cur_thr[:response_done].unlock
        cur_thr.kill
      end
    end
  end