Reordering instructions are performed at different levels. The compiler is most obvious, and the processor (which is on the go) is less obvious. However, the synchronization functions almost always constitute a fence that prevents reordering of instructions before and after the fence.
So, if your virtual lock calls pthread_mutex_*() , then your virtual functions contain a fence.
So the short answer is: No, this will not lead to errors.
There is also the volatile keyword, which, depending on the platform, can also create a fence. However, using volatile keywords makes it a lot harder to detect these barriers, because every time you use a function or variable that is volatile, you enter a fence. Therefore, the tip is that you use the platform synchronization features.
The only time you need to know about the fence is when you are not using concurrency objects to perform synchronization (for example, instead of bool instead of mutex).
source share