# File lib/monitor.rb, line 93
    def wait(timeout = nil)
      @monitor.instance_eval {mon_check_owner()}
      timer = create_timer(timeout)
      
      Thread.critical = true
      count = @monitor.instance_eval {mon_exit_for_cond()}
      @waiters.push(Thread.current)

      begin
        Thread.stop
        return true
      rescue Timeout
        return false
      ensure
        Thread.critical = true
        begin
          if timer && timer.alive?
            Thread.kill(timer)
          end
          if @waiters.include?(Thread.current)  # interrupted?
            @waiters.delete(Thread.current)
          end
          @monitor.instance_eval {mon_enter_for_cond(count)}
        ensure
          Thread.critical = false
        end
      end
    end