Use thread local storage instead of pthread_getspecific.