• Where does my thread-local data live ?

    From Bonita Montero@3:633/10 to All on Sat Nov 14 19:35:38 2026
    #include <Windows.h>
    #include <iostream>

    using namespace std;

    int main()
    {
    thread_local int i;
    MEMORY_BASIC_INFORMATION mbi;
    if( !VirtualQueryEx( GetCurrentProcess(), &i, &mbi, sizeof mbi ) )
    return EXIT_FAILURE;
    cout << "allocation base: " << (void *)mbi.AllocationBase << endl;
    cout << "region base: " << (void *)mbi.BaseAddress << endl;
    cout << "&i: " << (void *)&i << endl;
    cout << "region size: " << (double)mbi.RegionSize / 0x1.0p12;
    cout << " pages" << endl;
    }

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Bonita Montero@3:633/10 to All on Sun Nov 15 09:48:59 2026
    Am 14.11.2026 um 19:35 schrieb Bonita Montero:

    int main()
    {
    ˙˙˙˙thread_local int i;
    ˙˙˙˙MEMORY_BASIC_INFORMATION mbi;
    ˙˙˙˙if( !VirtualQueryEx( GetCurrentProcess(), &i, &mbi, sizeof mbi ) )
    ˙˙˙˙˙˙˙ return EXIT_FAILURE;
    ˙˙˙˙cout << "allocation base: " << (void *)mbi.AllocationBase << endl;
    ˙˙˙˙cout << "region base:˙˙˙˙ " << (void *)mbi.BaseAddress << endl;
    ˙˙˙˙cout << "&i:˙˙˙˙˙˙˙˙˙˙˙˙˙ " << (void *)&i << endl;
    ˙˙˙˙cout << "region size:˙˙˙˙ " << (double)mbi.RegionSize / 0x1.0p12;
    ˙˙˙˙cout << " pages" << endl;
    }

    Does anyone have a guess what this is good for ? ;-)

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Chris M. Thomasson@3:633/10 to All on Sun Nov 15 12:40:52 2026
    On 11/14/2026 10:35 AM, Bonita Montero wrote:
    #include <Windows.h>
    #include <iostream>

    using namespace std;

    int main()
    {
    ˙˙˙˙thread_local int i;
    ˙˙˙˙MEMORY_BASIC_INFORMATION mbi;
    ˙˙˙˙if( !VirtualQueryEx( GetCurrentProcess(), &i, &mbi, sizeof mbi ) )
    ˙˙˙˙˙˙˙ return EXIT_FAILURE;
    ˙˙˙˙cout << "allocation base: " << (void *)mbi.AllocationBase << endl;
    ˙˙˙˙cout << "region base:˙˙˙˙ " << (void *)mbi.BaseAddress << endl;
    ˙˙˙˙cout << "&i:˙˙˙˙˙˙˙˙˙˙˙˙˙ " << (void *)&i << endl;
    ˙˙˙˙cout << "region size:˙˙˙˙ " << (double)mbi.RegionSize / 0x1.0p12;
    ˙˙˙˙cout << " pages" << endl;
    }

    iirc, in the .tdata or .tss. But that might be for ELF. For Windows,
    damn... iirc, in the TIB?

    https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-tlsalloc

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Bonita Montero@3:633/10 to All on Tue Nov 17 12:04:07 2026
    Am 15.11.2026 um 21:40 schrieb Chris M. Thomasson:

    iirc, in the .tdata or .tss. But that might be for ELF. For Windows,
    damn... iirc, in the TIB?

    As thread-local data is per thread it isn't in the executable image.
    At least for Windows.

    https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-tlsalloc

    This is to allocate a TLS-slot for a new image.
    You almost never need this.


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Chris M. Thomasson@3:633/10 to All on Tue Nov 17 16:09:46 2026
    On 11/17/2026 3:04 AM, Bonita Montero wrote:
    Am 15.11.2026 um 21:40 schrieb Chris M. Thomasson:

    iirc, in the .tdata or .tss. But that might be for ELF. For Windows,
    damn... iirc, in the TIB?

    As thread-local data is per thread it isn't in the executable image.
    At least for Windows.

    What about:

    __declspec(thread) int x;


    https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/
    nf-processthreadsapi-tlsalloc

    This is to allocate a TLS-slot for a new image.
    You almost never need this.



    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Unknown@3:633/10 to All on Wed Nov 18 07:34:16 2026
    "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> wrote:

    What about:

    __declspec(thread) int x;

    Take a look at <https://skanthak.hier-im-netz.de/blunder.html#blunder114>
    as well as <https://skanthak.hier-im-netz.de/msvcrt.html#tls>

    Stefan
    --
    <https://www.duden.de/rechtschreibung/Kanthaken>

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Bonita Montero@3:633/10 to All on Wed Nov 18 15:25:04 2026
    Am 18.11.2026 um 01:09 schrieb Chris M. Thomasson:

    On 11/17/2026 3:04 AM, Bonita Montero wrote:

    As thread-local data is per thread it isn't in the executable image.
    At least for Windows.

    What about:
    __declspec(thread) int x;

    Better use C++11's thread_local since it cares for constructors
    and destructors.

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Chris M. Thomasson@3:633/10 to All on Wed Nov 18 12:59:24 2026
    On 11/18/2026 6:25 AM, Bonita Montero wrote:
    Am 18.11.2026 um 01:09 schrieb Chris M. Thomasson:

    On 11/17/2026 3:04 AM, Bonita Montero wrote:

    As thread-local data is per thread it isn't in the executable image.
    At least for Windows.

    What about:
    __declspec(thread) int x;

    Better use C++11's thread_local since it cares for constructors
    and destructors.

    Yeah. Also, in a dll: TlsAlloc and friends are the way to go. Iirc, in DLLMain, set everything up.

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Bonita Montero@3:633/10 to All on Thu Nov 19 16:45:53 2026
    Am 18.11.2026 um 21:59 schrieb Chris M. Thomasson:

    Yeah. Also, in a dll: TlsAlloc and friends are the way to go.
    Iirc, in DLLMain, set everything up.

    You can write your own DllMain without honouring TlsAlloc.
    The kernel does everything for you and places the right
    TLS-index in the thread-information block.


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Chris M. Thomasson@3:633/10 to All on Thu Nov 19 12:19:14 2026
    On 11/19/2026 7:45 AM, Bonita Montero wrote:
    Am 18.11.2026 um 21:59 schrieb Chris M. Thomasson:

    Yeah. Also, in a dll: TlsAlloc and friends are the way to go.
    Iirc, in DLLMain, set everything up.

    You can write your own DllMain without honouring TlsAlloc.
    The kernel does everything for you and places the right
    TLS-index in the thread-information block.


    Its been a while since I created a lot of DLL's in Windows, but:

    https://learn.microsoft.com/en-us/windows/win32/dlls/using-thread-local-storage-in-a-dynamic-link-library

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Bonita Montero@3:633/10 to All on Fri Nov 20 07:13:06 2026
    Am 19.11.2026 um 21:19 schrieb Chris M. Thomasson:
    Its been a while since I created a lot of DLL's in Windows, but: https://learn.microsoft.com/en-us/windows/win32/dlls/using-thread-local- storage-in-a-dynamic-link-library

    If you use static TLS, i.e. using __declspec(thread) or thread_local,
    you don't need to allocate your own TLS slot. The compiler does that
    for you.


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)