I need to perform a set of operations on a queue.Queue, specifically to go through it and pack duplicate contiguous elements. I also want to be sure there's only one thread accessing the queue during this set of operations. I see that the Queue object has a mutex, but I also assume it's for the queue to perform locking during its own operations. Having another mutex does not guarantee that the queue is not accessed by another thread in the meantime, unless I organize my code to lock the second mutex.
Is there a trick I am not aware of in order to perform these operations safely?