Threading: add TLS (thread-local storage) support