class Rufus::Scheduler::Job

def start_work_thread

def start_work_thread
  thread =
    Thread.new do
      Thread.current[@scheduler.thread_key] = true
      Thread.current[:rufus_scheduler_work_thread] = true
      loop do
        job, time = @scheduler.work_queue.pop
        break if @scheduler.started_at == nil
        next if job.unscheduled_at
        begin
          (job.opts[:mutex] || []).reduce(
            lambda { job.do_trigger(time) }
          ) do |b, m|
            lambda { mutex(m).synchronize { b.call } }
          end.call
        rescue KillSignal
          # simply go on looping
        end
      end
    end
  thread[@scheduler.thread_key] = true
  thread[:rufus_scheduler_work_thread] = true
    #
    # same as above (in the thead block),
    # but since it has to be done as quickly as possible.
    # So, whoever is running first (scheduler thread vs job thread)
    # sets this information
end