Difference between revisions of "Race Conditions Studio"
Line 18: | Line 18: | ||
{{Parallel|public static Map<String, Integer> countWords(Iterable<String> words)}} | {{Parallel|public static Map<String, Integer> countWords(Iterable<String> words)}} | ||
+ | =Testing Your Solution= | ||
+ | ==Correctness== | ||
+ | {{TestSuite|RaceConditionTestSuite|racecondition.studio}} | ||
+ | |||
+ | <!-- | ||
=Where to Start= | =Where to Start= | ||
Line 40: | Line 45: | ||
This method should do the same thing as the createLetterToScoreMap method, but it should use an array of entries to avoid a data race. To do this, the <code>EntryUtils.createEntryArray()</code> method should come in handy. For each string within the collection, get the point value as you did before and create a new entry for the array using the <code>EntryUtils.createEntry()</code> method. You can convert the array of entries into a map using the <code>EntryUtils.createTreeMapFromArrayOfEntries()</code> method. | This method should do the same thing as the createLetterToScoreMap method, but it should use an array of entries to avoid a data race. To do this, the <code>EntryUtils.createEntryArray()</code> method should come in handy. For each string within the collection, get the point value as you did before and create a new entry for the array using the <code>EntryUtils.createEntry()</code> method. You can convert the array of entries into a map using the <code>EntryUtils.createTreeMapFromArrayOfEntries()</code> method. | ||
+ | --> |
Revision as of 10:08, 13 February 2018
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 take in a collection of strings, clean up each string, and add it into another collection of strings concurrently. You will also take in a collection of words, assign a point value to each word, and then put it into a map. Although not terribly exciting, the point of this studio is to teach you how to avoid data races when performing concurrent tasks. In order to accomplish these tasks, you will use the ConcurrentLinkedQueue, array, and ConcurrentHashMap classes.
Code To Debug
Word Score
class: | SuspectWordScore.java | |
methods: | toCleanedWordsViaArray | |
package: | racecondition.studio.wordscore | |
source folder: | student/src/main/java |
method: public static List<String> toCleanedWordsViaArray(Collection<String> sourceLines)
(parallel implementation required)
Merge Sort
class: | SuspectMergeSort.java | |
methods: | parallelMergeSortKernel | |
package: | racecondition.studio.mergesort | |
source folder: | student/src/main/java |
method: private static void parallelMergeSortKernel(int[] data, int lowInclusive, int highExclusive, int threshold, Combiner combiner)
(parallel implementation required)
Word Count
class: | SuspectWordCountTest.java | |
methods: | countWords | |
package: | racecondition.studio.wordcount | |
source folder: | student/src/main/java |
method: public static Map<String, Integer> countWords(Iterable<String> words)
(parallel implementation required)
Testing Your Solution
Correctness
class: | RaceConditionTestSuite.java | |
package: | racecondition.studio | |
source folder: | testing/src/test/java |