synchronize main and pipe and input