Properly wake semaphores in priority order.