Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thread Local Storage

When you allocate some TLS for thread A in a slot, can you then access that same slot from Thread B?

Is it internally synchronized or how does that work?

like image 346
Tony The Lion Avatar asked Jul 03 '26 07:07

Tony The Lion


1 Answers

The local variables of a function are unique to each thread that runs the function. This can be accomplished with help of TLS which as already mentioned is local for each thread. If you want to share some data between threads there are several options starting from using global or static variables up to memory mapped files and etc... also check thread synchronization if you need to share data between threads.

The following diagram illustrates how TLS works.

For more details check MSDN.

alt text
(source: microsoft.com)

like image 72
Incognito Avatar answered Jul 05 '26 20:07

Incognito