O'Reilly logo

Efficient C++ Performance Programming Techniques by David Mayhew, Dov Bulka

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Share Nothing

Reduction in sharing is good, but nothing beats eliminating contention altogether. Instead of sharing a resource, you can sometimes eliminate sharing completely by giving each thread its own private resource. Recall from the previous section that each Web server worker thread (in our implementation) maintained a pointer to its private data object of type ThreadSpecificData:

class ThreadSpecificData {
    HTRequest *reqPtr;   // Attributes of current HTTP request
    ...
};

The reqPtr member was a pointer to an HTRequest object containing information about the current HTTP request. At the beginning of each request, the worker thread created a brand new object of type HTRequest:

 ThreadSpecificData *HTInitRequest(StreamSocket sock) { ... ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required