Use thread id rather than pthread_self.

Ideally a tls variable would be faster.