views:

94

answers:

3

Are there languages that support process common memory in one address space and thread specific memory in another address space using language features rather than through a mechanism like function calls?

process int x;
thread int y;
A: 

The Visual C++ compiler allows the latter through the nonstandard __declspec(thread) extension - however, it is severly limited, since it isn't supported in dynamically loaded DLLs.

The first is mostly supported through an extern declaration - unless dynamically linked libraries come into play (which is probably the scenario you are looking for).

I am not aware of any environment that makes this as simple as you describe.

peterchen
A: 

ThreadStatic attribute in C#

ripper234
A: 

C++0x adds the "thread_local" storage specifier, so in namespace (or global) scope your example would be

int x;              // normal process-wide global variable
thread_local int y; // per-thread global variable

You can also use thread_local with static when declaring class members or local variables in a function:

class Foo {
    static thread_local int x;
};

void f() {
    static thread_local int x;
}

Unfortunately, this doesn't appear to be one of the C++0x features supported by Visual Studio 2010 or planned GCC releases.

Jesse Hall