introduce mutex to sync writing messages