Export (0) Print
Expand All
Expand Minimize

Compiler Error C2384

'member' : cannot apply __declspec(thread) to a member of a managed class

The thread __declspec modifier cannot be used on a member of a managed.

Static TLS can only be used for statically loaded DLLs -- the DLL must be statically loaded when the process starts.

The following line generates C2384:

// C2384.cpp
// compile with: /clr /c
public ref class B {
public:
   __declspec( thread ) static int tls_i = 1;   // C2384

   // OK
   [System::ThreadStaticAttribute]
   static int tls_i;
};

The following line generates C2384:

// C2384_b.cpp
// compile with: /clr:oldSyntax /c
public __gc class B {
public:
   __declspec( thread ) static int tls_i = 1;   // C2384

   // OK
   [System::ThreadStaticAttribute]
   static int tls_i;
};

Community Additions

ADD
Show:
© 2014 Microsoft