Sunday, August 4, 2019

c++ - Using __thread in c++0x



I read that there was a new keyword in C++: it's __thread from what I've read.



All I know is that it's a keyword to be used like the static keyword but I know nothing else. Does this keyword just mean that, for instance, if a variable were declared like so:



__thread int foo;



then anything to do with that variable will be executed with a new thread?


Answer



It's thread_local, not __thread. It's used to define variables which has storage duration of the thread.



thread_local is a new storage duration specifier added in C++0x. There are other storage duration : static, automatic and dynamic.



From this link:





thread local storage duration (C++11 feature). The variable is allocated when the thread begins and deallocated when the thread ends. Each thread has its own instance of the variable. Only variables declared thread_local have this storage duration.







I think the introduction of this keyword was made possible by introducing a standardized memory model in C++0x:




No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...