Phaser Per Participant Legged Race Assignment
Motivation???
While the Phaser Per Team implementation of the N/2 3 legged races is superior in many ways, some students in the past have chosen to create a Phaser per participant and coordinate the tasks by arriving on the task's phaser and awaiting on the task's partner's phaser.
Again, the Phaser Per Team approach is the cleaner and superior version, however this approach seems worthy of a side-quest (if for no other reason than to provide experience with separating arrive and awaitAdvance (even if, granted, there is no work between the arrive and awaitAdvance to justify it)).
Code To Implement
class: | PhaserPerParticipantLeggedRace.java | |
methods: | constructor phaserCreator takeSteps |
|
package: | leggedrace.exercise | |
source folder: | student/src/main/java |
method: public void takeSteps(Participant[] participants, int stepCount)
(parallel implementation required)
Use provided int getPartnerIndex(int)
to find the partner for a participant
private static int getPartnerIndex(int index) {
boolean isOddIndex = (index&0x1) == 0x1;
if( isOddIndex ) {
return index - 1;
} else {
return index + 1;
}
}
Testing
class: | _PhaserPerParticipantLeggedRaceTestSuite.java | |
package: | leggedrace.sidequest | |
source folder: | testing/src/test/java |