Use thread local storage for thread index