PETSC_TLS#

Marks a variable as thread-local when PETSc is configured with thread safety

Synopsis#

#include <petscmacros.h>
PETSC_TLS type variable;

Notes#

When configured with --with-threadsafety=1, each thread has its own instance of the variable, whose lifetime is the lifetime of that thread. With --with-threadsafety=0, PETSC_TLS expands to nothing.

In C, this macro uses C11 _Thread_local. In C++, it uses C++11 thread_local, except with Clang, where it uses _Thread_local to allow C++ code to access thread-local variables defined in C without requiring C++ initialization wrappers.

Use PETSC_EXTERN PETSC_TLS for an exported declaration or PETSC_INTERN PETSC_TLS for an internal declaration.

Example Usage#

  // In a header
  PETSC_EXTERN PETSC_TLS int counter;

  // In the source file that defines the variable
  PETSC_TLS int counter = 0;

See Also#

PetscStack, PetscStackView()

Level#

developer

Location#

include/petscmacros.h


Index of all Sys routines
Table of Contents for all manual pages
Index of all manual pages