Using mutex to ensure proper scheduling