How to store data when using parallel processing

Andrew Chapman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Aug 26 17:26:33 PDT 2017


Hi all, just wanting some advice on parallel processing and 
specifically how to deal with access violations.

I am reading a list of words from a file like this:

auto fileHandle = File("wordlist.txt", "r");

string word;
string[] words;
string[ulong] hashMap;

while ((word = fileHandle.readln()) !is null) {
	words ~= word;
}

Then I'm doing some processing on the words.  I want to make this 
run as quickly as possible so I am doing the processing across 
the cores of my CPU like this:

foreach (thisWord; parallel(words)) {
	string wordLower = thisWord.strip().toLower();
	ulong key = keyMaker.createKeyForWord(wordLower);

         // hashMap[key] = wordLower;
}

The question is, in the above loop, how can I make the commented 
out line work without having an access violation.  Do I need to 
use a different data structure?  Or rethink what I'm doing?

Thanks in advance.
Andrew.


More information about the Digitalmars-d-learn mailing list