versao funcional com threads