merged schedule_next_thread() and mutex lock