Use condition variables instead of an array of integers.