For instance:
#include <thread> thread_local int n = 1; void f() { ++n; // is n initialized here for each thread or prior to entering f()? } int main() { std::thread ta(f); std::thread tb(f); ta.join(); tb.join(); }
It is still not entirely clear from here when n is initialized.
Simple enough and everything is in accordance with the specification. nwill be initialized whenever a new thread starts - before you enter any thread-related functions.
n
To be precise, it will be initialized three times.
Source: https://habr.com/ru/post/1629580/More articles:OAuth2 Update token. How to keep it client side - javascriptDisplay too long - javascriptCan a variable be used as a property? - c #how to use asciidocltor-maven-plugin to generate html documentation from ascii documents created using springfox-staticdocs in ascii format - javaHow to remove the space below an empty divline div block (and why is it anyway?) - htmlFind a word not surrounded by alpha char - pythonHidden redirects to a hacked site? - redirectLocal Mesosphere Development - dockerFinding a variable address from another process - c ++POSIX defines behavior when sending NUL to the terminal? - bashAll Articles