add lock on buf