Obviously, lists themselves are not thread safe. However, some operations on them are atomic meaning that no thread can force itself into the execution of that instruction.
Assuming that L is a list:
L = [1,2,3,4]
I know that
x = L[2] # is atomic.
Now assuming that I have a list of list;
L = [ [1, 2, 3], [4, 5, 6] ]
Further, assume the entire list structure is fixed but the individual values are not i.e. there will always be 2 lists of 3 items.
I know that L[1] = [7,8,9]
is atomic meaning L[1]
will at some point change to exactly [7,8,9]
however there is no guarantee when or for how long.
- Is
L[1][2] = 10
atomic? x = L[1]
is still atomic right?- Do the answers to 1. and 2. hold irrespective of what the list items are i.e. list of objects?
I think all the answers are yes, but don't know.