you can use queueMutex.lock() and queueMutex.unclock() in such cases. code with scopes is not clear enough