Compiler Error C3057
Visual Studio 2015
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at Compiler Error C3057.
symbol' : dynamic initialization of 'threadprivate' symbols is not currently supported
The initialized value of a symbol used in a threadprivate clause must be known at compile time.
The following sample generates C3057:
// C3057.cpp
// compile with: /openmp /c
extern int f();
int x, y = f();
int a, b;
#pragma omp threadprivate(x, y) // C3057
#pragma omp threadprivate(a, b)
int main() {
// Delete the following 4 lines to resolve.
#pragma omp parallel copyin(x, y)
{
x = y;
}
#pragma omp parallel copyin(a, b)
{
a = b;
}
}
The following sample generates C3057:
// C3057b.cpp
// compile with: /openmp /c
extern int Initialize();
int main() {
#pragma omp parallel
{
static int var = Initialize();
#pragma omp threadprivate(var) // C3057
}
// OK
#pragma omp parallel
{
static int var2;
static bool initialized2;
#pragma omp threadprivate(var2, initialized2)
if (!initialized2) {
var2 = Initialize();
initialized2 = true;
}
}
}
Show: