Added a mutex to ensure synchronized access to the with_result queue