Race Condition Translation Assignment

From CSE231 Wiki
Revision as of 14:25, 3 September 2024 by Cosgroved (talk | contribs) (→‎Client)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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 Debugging icon.png
methods: translateAllWords
package: racecondition.translate.warmup
source folder: student/src/main/java

method: public String[] translateAllWords(String[] words) Parallel.svg (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: Java.png
methods: main
package: racecondition.translate.client
source folder: src//java
public static void main(String[] args) throws InterruptedException, ExecutionException {
	String text = "Trust me, Wilbur. People are very gullible. They'll believe anything they see in print.";
	// - E.B. White, Charlotte’s Web
	String[] words = toWords(text);
	//		PigLatinTranslator pigLatinTranslator = new SequentialPigLatinTranslator();
	PigLatinTranslator pigLatinTranslator = new ParallelPigLatinTranslator();
	String[] translatedWords = pigLatinTranslator.translateAllWords(words);
	paddedPrintln(words);
	paddedPrintln(translatedWords);
}

Testing Your Solution

Correctness

class: _TranslateTestSuite.java Junit.png
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