manipulate buf under mutex