Add volatile for thread safety to writecounter