Thread safety via TSD
Prior to the TLS technique that we just saw (that is, before Linux 2.6 and gcc 3.3), how did one guarantee writing a new API to be thread safe? A much older technology exists, called TSD.
In a nutshell, TSD is a more complex solution from the application developer's viewpoint—more work must be done to achieve the very same end result that TLS so easily gives us; that of making a function thread-safe.
With TSD, the thread-safe routine must invoke an initializer function (usually done with pthread_once(3)), which creates a unique thread-specific data key (using the pthread_key_create(3) API). This initializer routine associates a thread-specific data variable (such as the iobuf buffer pointer in our example) with that ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access