I need to multithreadedly use the following code in python for homework (turned it into pseudocode). I just wanted to see if my decision had anything missing before I start.
L = [2, 3, 4, ...]
sums = [0, 0, 0, ...]
for item in L:
sums[hash(item)] += func(item)
My solution is to split the statement inside the for loop: save the "item" variable in the temp variable, block L whenever I do this, and then calculate the information hash (temp_item) and func (temp_item) into more temporary variables. Then lock L and update it.
Is this the best solution? Only lock variables when I take or update.
This is more about learning parallelism than the limitations of python.
source
share