Leandros Leandros - 8 months ago 72
C Question

Saving data in Win32 TIB

The Thread-Information Block should be widely known, and can be used to access a few important information. But can I use it to save data?

I've seen the structure has a slot for an arbitrary pointer at offset

(x86) /

Can I use this pointer to point to my own thread structure from my own scheduler? Or does it get overridden by something else?


You can use the TlsAlloc() function to allocate thread local storage. Each TLS index can save a pointer-sized value, so you can use a TLS slot to point to a larger allocated data structure if needed.

See Using Thread Local Storage for an example.