Thread ID problem

Hello

In my software, i get the id of a thread when i create it, with

1
2
pthread_create( &thread[0], NULL, threadRun, this);
curThreadID = thread[0];


then in threadRun i am checking the ID of the active thread with

activeThreadID=(unsigned int)pthread_self()

if i use only one thread, on Redhat 5.8 these two IDs are same. But now i passed to Redhat 6.3 and these IDs are different.

what can be the reason? and how can i get the same ids on Redhat 6.3?

can the kernel version cause this problem? on Redhat 6.3, kernel version is 2.6.32-279.9.1.el6.x86_64 whereas on 5.8 the version is 2.6.18-308.8.1.el5.

Thanks
Last edited on
Can you write a minimal program that reproduces the problem?
What are the types of the variables involved? (in particular, is "thread" an array of unsigned int or pthread_t?
yeah sure

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
long curThreadID;
int NUM_THREADS=2;

void *threadRun(void *arg)
{

cout << "activeThread: " << (unsigned int)pthread_self() << endl;

}

void main (int argc, char *argv[]) {


pthread_t* thread = new pthread_t[NUM_THREADS];

 for(t=0; t<NUM_THREADS; t++) {
         pthread_create( &thread[t], NULL, threadRun, this);
	
         if(t==0){
		curThreadID = thread[i];
	        cout << "curThred: " << curThreadID << endl;
 }

 for(t=0; t<NUM_THREADS; t++) 
                pthread_join( thread[i], &status);

}


hope this helps.
Last edited on
Topic archived. No new replies allowed.