Background: I create many small utilities for some very specialised data processing. Often, I am the only user. I don't even think about multi-threaded programming, because the run-time performance is by far sufficient for my use cases. The critical resource is my programming time. So I want to avoid any extra effort required for multi-threaded programming.
However, it seems there is a risk, that my source code gets executed in a multi-threaded context, when I reuse my code in future.
According to CppCoreGuidelines :
Be careful: there are many examples where code that was “known” to never run in a multi-threaded program was run as part of a multi-threaded program. Often years later. Typically, such programs lead to a painful effort to remove data races. Therefore, code that is never intended to run in a multi-threaded environment should be clearly labeled as such and ideally come with compile or run-time enforcement mechanisms to catch those usage bugs early.
Most of the suggestions in the same source actually get me started with multi-threaded programming. The one suggestion, which I prefer to follow says:
Refuse to build and/or run in a multi-threaded environment.
So my question is, how do I do that? E.g. is there an include file, #pragma or so to ensure single threaded build / execution of everything within a source file?