define thread-local variables. The header <threads.h>, if supported, defines thread_local as a synonym for that keyword. Example usage: #include <threads.h> thread_local int foo = 0; C++11 introduces the thread_local keyword which can be used in the following cases Namespace level (global) variables File static variables Function static variables Static member variables Aside from that, various compiler implementations provide specific ways to declare thread-local variables: Solaris Studio C/C++, IBM XL C/C++, GNU C, Clang and Intel C++ Compiler (Linux systems) use the syntax: __thread int number; Visual C++, Intel C/C++ (Windows systems), C++Builder, and Digital Mars C++ use the syntax: __declspec(thread) int number; C++Builder also supports the syntax: int __thread number; On Windows versions before Vista and Server 2008, __declspec(thread) works in DLLs only when those DLLs are bound to the executable, and will not work for those loaded with LoadLibrary() (a protection fault or data corruption may occur). Common Lisp (and maybe other dialects) Common Lisp provides a feature called dynamically scoped variables. Dynamic variables have a binding which is private to the invocation of a function and all of the children called by that function. This abstraction naturally maps to thread-specific storage, and Lisp implementations that provide threads do this. Common Lisp has numerous standard dynamic variables, and so threads cannot be sensibly added to an implementation of the language without these variables having thread-local semantics in dynamic binding. For instance the standard variable *print-base* determines the default radix in which integers are printed. If this variable is overridden, then all enclosing code will print integers in an alternate radix: ;;; function foo and its children will print ;; in hexadecimal: (let ((*print-base* 16)) (foo)) If functions can execute concurrently on different threads, this binding has to be properly thread-local, otherwise each thread will fight over who controls a global printing radix. D In D version 2, all static and global variables are thread-local by default and are declared with syntax similar to "normal" global and static variables in other languages. Global variables must be explicitly requested using the shared keyword: int threadLocal; // This is a thread-local variable. shared int global; // This is a global variable shared with all threads. The shared keyword works both as the storage class, and as a type qualifier – shared variables are subject to some restrictions which statically enforce data integrity. To declare a "classic" global variable without these restrictions, the