Fix a potential synchronisation problem due to compiler optimisations.
The problem seems not to have occurred in practice, but we don't want
it to be triggered by a future compiler version.