Try using a binary search for the thread ready queue.