I have a function call that starts 10 threads. Before the start of these threads , I have
from collections import defaultdict
output = defaultdict(dict)
and output is empty.
Each thread will generate data to write to the dictionary.
Something like:
output['water'] = 'h20'
output['fire'] = 'delta of oxygen'
....
The threads will only add items and they do not iterate over any of the other items or modify any other items. output['water']
being an item that is different from output['fire']
. I can also guarantee that no two threads are going to create the same item. That is, each thread T has a unique i. In code: output[i] is unique per thread.
Is this dictionary thread safe in this regard?