What is a realistic performance loss due to the fact that in C ++ 0x all other threads should wait in this case:
string& program_name() { static string instance = "Parallel Pi"; return instance; }
Let's look at the optimal scenario: the programmer was very careful that even with 100 threads only the main thread calls the program_name function, all other 99 workflows are busy with useful things, which does not require calling this "critical" one.
I quote the new C ++ 0x-Std Β§ 6.7. (4) stmt.decl
... such an object is initialized when the first control passes through its declaration ... If the control enters the declaration simultaneously during the initialization of the object, simultaneous execution should wait for the initialization to complete ...
What are the realistic overheads that a real-world compiler needs to impose on me so that this static initialization is performed in accordance with the requirements of the standard.
- Is a lock / mutex required? I assume that they are expensive, even if they are not needed?
- If they are expensive, will this be done by less expensive mechanisms?
edit: added string ...
towi source share