Regarding standards, yes, you should use a mutex. Failure to do so will result in undefined behavior. In practice, most machine architectures will not have any problems with this. Future versions of the C (C1x) standard will have atomic types, which, if used here, will definitely do the job without blocking (although it is possible, using an internal lock, on broken arches that do not have real atomism).
R .. source
share