I have a threaded program consisting of a Consumer
class and a Producer
class. Currently, I use a Fifo queue.Queue
in the implementation, where the producer put
s the data at the end of the queue and the consumer get
s it.
However, I would like to add a feature where, if necessary, the Consumer
can put
back the (perhaps slightly modified) item that it get
s by putting it back at the front of the Queue
(so that the next item returned by get
is the item just added, like in a stack).
I know this is possible with deque
s, but I've read here that they are only thread-safe for append()
and popleft()
. For the purposes above I'll also need to use appendleft()
.
Is there a thread-safe data structure that has the features of a deque
? If not, could I make the deque
thread-safe by putting in my own locks whenever I use appendleft
?