Fix locking in GetNextTask.