Re: thread local variable



Alex Blekhman wrote:
`__declspec(thread)' modifier can be applied to static variables only.

Hmmm, that statement is pretty misleading, 'static' is not sufficient to
describe the requirement:

namespace answer {
int __declspec(thread) fourtytwo;
}

This is perfectly valid without any 'static'. Further, the 'namespace' is
only to demonstrate that the declaration is not local or at class scope, it
could have been in the global namespace or an anonymous one, too.

* You can specify the thread attribute only on data items
with static storage duration.

"static storage duration" is the key here, variables at namespace scope also
fall under this category.

Uli

.



Relevant Pages

  • Re: thread local variable
    ... Microsoft MVP - Visual C++ ... Further, the 'namespace' is ... only to demonstrate that the declaration is not local or at class scope, ... "static storage duration" is the key here, ...
    (microsoft.public.vc.language)
  • Re: Confused about iterator_tags and iterator_traits
    ... >>empty statements at namespace or class scope. ... Versus adding the addition of a semicolon ... now as a compiler implementor can you see how to fix the grammar ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Compiler cant see class
    ... >>>Is your class declaration inside a function? ... the class scope is local to the function. ... >void MyFunction() ... I will qualify that the use of namespace is ...
    (microsoft.public.vc.language)
  • Re: Return struct from function
    ... When I use the datatype inside the function I don`t have to refrence ... The return type is not yet in class scope, the body of the function is. ... but can't find it defined anywhere in namespace ... compiler past the return type and into the function body. ...
    (microsoft.public.vc.language)
  • Re: STL and "function try blocks"
    ... defined only in namespace or class scope. ... global namespace it fails. ... Global namespace _is_ namespace scope. ... shall be defined only in namespace or class scope." ...
    (microsoft.public.vc.stl)

Loading