Fix a bug in multiple queues in multi threaded mode