Race Condition Translation Assignment
Contents
Motivation
Race conditions can lead to difficult bugs to find and fix. We gain experience finding them and fixing them.
Background
In this studio, you will translate an array of texts in parallel.
The Core Questions
Really think about these questions in each case. Knowing the answers to these will tell you where the problem is.
- What are the tasks?
- What is the data?
- Is the data mutable?
- If so, how is it shared?
Code To Investigate
SequentialPigLatinTranslator
package racecondition.translate.antiquated;
public class SequentialPigLatinTranslator extends AbstractPigLatinTranslator {
@Override
public String[] translateAllWords(String[] words) {
String[] translatedWords = new String[words.length];
for (int i = 0; i < words.length; ++i) {
translatedWords[i] = translateWord(words[i]);
}
return translatedWords;
}
}
Code To Debug
TranslationUtils
class: | ParallelPigLatinTranslator.java | |
methods: | translateAllWords | |
package: | racecondition.translate.warmup | |
source folder: | student/src/main/java |
method: public String[] translateAllWords(String[] words)
(parallel implementation required)
public class ParallelPigLatinTranslator extends AbstractPigLatinTranslator {
@Override
public String[] translateAllWords(String[] words) throws InterruptedException, ExecutionException {
throw new NotYetImplementedException();
}
}
Client
class: | TranslationClient.java | DEMO: |
methods: | main | |
package: | racecondition.translate.client | |
source folder: | src//java |
The client invokes your method with a Pig Latin tranlator:
String[] translatedWords = TranslationUtils.translate(words, new PigLatinTranslator());
Testing Your Solution
Correctness
class: | _TranslateTestSuite.java | |
package: | racecondition.translate.warmup | |
source folder: | testing/src/test/java |
Pledge, Acknowledgments, Citations
file: | race-condition-translate-pledge-acknowledgments-citations.txt |
More info about the Honor Pledge