Replaced __declspec(thread) with TlsAlloc.

Variables created within a DLL with __declspec(thread) may not get a TLS
slot on Windows XP, leading to segfaults on use.  Moving to TlsAlloc
works around this.