Wrap the write in a mutex