[Tutor] why list is not thread-safe, but deque and queue are thread-safe?

Alan Gauld alan.gauld at btinternet.com
Wed May 2 19:02:29 CEST 2012

On 02/05/12 17:13, Lion Chen wrote:
> i have read it, as the "Answer" said, seems like deque is not
> thread-safe either, because deque has the operator +=, and others like
> that.

I'm no expert and have never used dequeue.
But I notice the documentation says:

"""Deques are a generalization of stacks and queues... Deques support 
thread-safe, memory efficient appends and pops from either side of the 
deque with approximately the same O(1) performance in either direction."""

So only append() and pop() are listed as being thread safe. If you use 
any other operation I read that as being a risk.

Alan G
Author of the Learn to Program web site

More information about the Tutor mailing list