Chapter 21. Thread-Local Storage

In this chapter:

Dynamic TLS

Static TLS

Sometimes it’s helpful to associate data with an instance of an object. For example, window extra bytes associate data with a specific window by using the SetWindowWord and SetWindowLong functions. You can use Thread Local Storage (TLS) to associate data with a specific thread of execution. For example, you can associate the creation time of a thread with a thread. Then, when the thread terminates, you can determine the thread’s lifetime.

The C/C++ run-time library uses TLS. Because the library was designed years before multithreaded applications, most functions in the library are intended for use with single-threaded applications. The _tcstok_s function is an excellent example. ...

Get Windows® via C/C++, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.