Local stream storage

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

Internal synchronization or how does it work?

+3
source share
3 answers

Local function variables are unique to each thread that performs a function. This can be done using TLS, which, as already mentioned, is local to each flow. If you want to share some data between streams, there are several options, starting with the use of global or static variables and memory-mapped files, etc ... also check the synchronization of streams if you need to exchange data between streams.

The following diagram shows how TLS works.

See MSDN for more details .

alt text http://i.msdn.microsoft.com/dynimg/IC495837.png

+3
source

, - , - , , .

, .

+4

, "" . TLS "" . x86/x84 - - "" TLS , . - .

No synchronization is required as each thread sees different data. If, of course, you do not want to store the same object in TLS of two different flows, then this is a different story, but this is a completely contrived case - the exchange does not occur due to TLS.

+3
source

Source: https://habr.com/ru/post/1751884/


All Articles