Queues: fix thread safety