Subj : Re: Any overhead to pthread getspecific() (a.k.a. thread-local variables)? To : comp.programming.threads From : Jonathan Adams Date : Mon May 09 2005 09:37 pm In article , Adam Ierymenko wrote: > I am curious about what sort of overhead I should expect from using > getspecific() frequently in a program? I am implementing multithreaded > low-contention (nearly lock-free) memory management in C++ using > thread-local memory pools and so this will be getting called frequently to > get the current thread-local memory pool. Why don't you test it yourself? It's certainly easy to imagine a hugely expensive implementation. > I would assume that the cost of getspecific() is probably about equivalent > to a function call plus an array lookup on most architectures, but I would > like to see if anyone knows of any reason why it might be more. On Solaris (9, 10, or 8 with liblwp), that's about the cost of it; two or three data loads, a compare or two, and return. > The OS is Linux, but I am curious about other architectures as well since > I want this to be portable. It's heavily implementation-dependent. Cheers, - jonathan .