sync using mutex instead of while loop