unsafe __gshared keyword must be used: __gshared int global; // This is a plain old global variable. Java In Java, thread-local variables are implemented by the class object. ThreadLocal holds variable of type T, which is accessible via get/set methods. For example, ThreadLocal variable holding Integer value looks like this: private static final ThreadLocal<Integer> myThreadLocalInteger = new ThreadLocal<Integer>(); At least for Oracle/OpenJDK, this does not use native thread-local storage in spite of OS threads being used for other aspects of Java threading. Instead, each Thread object stores a (non-thread-safe) map of ThreadLocal objects to their values (as opposed to each ThreadLocal having a map of Thread objects to values and incurring a performance overhead). .NET languages: C# and others In .NET Framework languages such as C#, static fields can be marked with the ThreadStatic attribute: class FooBar { [ThreadStatic] private static int _foo; } In .NET Framework 4.0 the System.Threading.ThreadLocal<T> class is available for allocating and lazily loading thread-local variables. class FooBar { private static System.Threading.ThreadLocal<int> _foo; } Also an API is available for dynamically allocating thread-local variables. Object Pascal In Object Pascal (Delphi) or Free Pascal the threadvar reserved keyword can be used instead of 'var' to declare variables using the thread-local storage. var mydata_process: integer; threadvar mydata_threadlocal: integer; Objective-C In Cocoa, GNUstep, and OpenStep, each NSThread object has a thread-local dictionary that can be accessed through the thread's threadDictionary method. NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary]; dict[@"A key"] = @"Some data"; Perl In Perl threads were added late in the evolution of the language, after a large body of extant code was already present on the Comprehensive Perl Archive Network (CPAN). Thus, threads in Perl by default take their own local storage for all variables, to minimise the impact of threads on extant non-thread-aware code. In Perl, a thread-shared variable can be created using an attribute: use threads; use threads::shared; my $localvar; my $sharedvar :shared; PureBasic In PureBasic thread variables are declared with the keyword Threaded. Threaded Var Python In Python version 2.4 or later, local class in threading module can be used to create thread-local storage. import threading mydata = threading.local() mydata.x = 1 Ruby Ruby can create/access thread-local variables using []=/[] methods: Thread.current[:user_id] = 1 Rust Thread-local variables can be created in Rust using the macro provided by the Rust standard library: use std::cell::RefCell; use std::thread; thread_local!(static FOO: RefCell<u32> = RefCell::new(1)); FOO.with(|f| { assert_eq!(*f.borrow(), 1); *f.borrow_mut()