Add mutex while scanning for hosts

This PR intends to fix isse #380