Details
-
Improvement
-
Resolution: Done
-
Major - P3
-
None
-
None
-
Fully Compatible
-
Service Arch 2020-02-10, Service Arch 2020-02-24, Service Arch 2020-03-09
Description
There are myriad functions that are only safe to call in single-threaded context, such as by Mongo initializer code.
Two alternative designs here:
1. stdx::thread uses a std::once initialization to transition a global boolean to false, indicating that the system is (potentially) no longer single threaded. Initialization and similar functions can assert on this global boolean (via an observer.)
2. Create an object which is constructible only by `int main(...)`, and pass this object to initializer functions by const reference. When main is going to launch its first thread, call into a `multithread_main` function which does not take the `SingleThreaded` mode object (token) as an argument – thus making it buried (and lost forever) in main.
The first design is simple to implement, but it is a runtime-check. The second design is a partial compile-time guarantee of threading concerns.