Reputation: 193
I have code like this:
arr = [Queue() for _ in range(10)]
And some threads will use the list at the same time. such as arr[0].get()
. I'm curious whether it is threadsafe. I know Queue()
is threadsafe in python. However, I do not know whether [Queue()]
is threadsafe.
Upvotes: 1
Views: 159
Reputation: 77347
Lists are read-safe. As long as no code is changing the size of the list, which would make indexing the list unsafe, you can read it from all of the threads. Since the only objects in the list are thread safe queues, you are good to go.
arr[0].push("foo")
bar = arr[0].pop()
don't change the list itself and are safe.
Upvotes: 1