Add mutex to while scanning for hosts

This PR intends to fix isse #380