Race Condition Translation Assignment

From CSE231 Wiki
Revision as of 07:08, 24 January 2023 by Cosgroved (talk | contribs)
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 Debug

TranslationUtils

class: TranslationUtils.java Debugging icon.png
methods: translate
package: racecondition.translate.warmup
source folder: student/src/main/java

method: String[] translate(String[] words, TaskFunction<String, String> translator) Parallel.svg (parallel implementation required)

Future<Void>[] futures = new Future[words.length];
String[] translatedWords = new String[words.length];
int[] array = { 0 };
for (array[0] = 0; array[0] < words.length; ++array[0]) {
	futures[array[0]] = void_fork(() -> {
		translatedWords[array[0]] = translator.apply(words[array[0]]);
	});
}
join(futures);
return translatedWords;

Client

class: TranslationClient.java DEMO: Java.png
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 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