putting the elements on an array simplifies the exit conditions and the synchronization code