News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Amazed or Mortified?

Started by TBRANSO1, January 24, 2019, 03:44:48 PM

Previous topic - Next topic

aw27

While knowledge about TLS is indeed very educative we can, in many cases, do without them. First, we can and most use local variables as much as possible - they are 100% thread safe and disappear when the thread terminates. Second, we can work with synchronization objects like mutexes to access a single non-threaded global variable in the cases where the values are to be accumulated. Finally, we can use an indexed global variable with an index per thread.

hutch--

There is a technique that I use from time to time with multi-threaded code that calls the same thread more that once, something you would use to handle multiple internet connections, create a structure in each thread as it is started having passed any required information to the start of the thread and then pass the address of that structure to any stage up the call tree so that data is accessible from any point in that thread. Works effectively like a GLOBAL but is created on the stack when the thread starts.

Any memory you allocate within this system is fully independent of any other and you can create as many threads as you have memory and thread handles to deal with. I am sure that TLS has its uses but I have not found one yet.