Well, I'm kind of new to this concept but it is TLS i assume.
I mean a global variable declared like this:

Code:
__declspec(thread) int g_threadnum;

void test() {
  if(g_threadnum==0) {
  }
  if(g_threadnum==1) {
  }
}

void threadfunc(int threadnum) {
  g_threadnum=threadnum;
  test();
}
What I am trying to do is "mark" each thread with a variable so that each thread can instantly know "I am thread number X". These checks will be performed frequently, so I'm looking for the fastest method.

I was previously passing threadnum on into all subroutines of the thread function but after reading about TLS i realize there may be more efficient ways of doing this.