What is thread id thread_t data type in ia64 platform
Hi,
Recently I faced an issue with thread ID. I find whenever I create thread , it always gives me 64-bit long int. And always I find it can not be converted to 32-bit as it will truncate.
I read some topic in google, that thread ID is just not a long int, it can be pointer or structure .
May I know what exactly thread ID is in below platform type ?
Linux Node2 2.6.10-telco-1.46-mckinley-smp #1 SMP Fri May 30 18:29:43 UTC 2008 ia64 GNU/Linux
#include <linux/unistd.h>
#include <sys/types.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#define NUM_THREADS 5
void *PrintHello(void *threadid)
{
int tid;
tid = (int)threadid;
printf("Hello World! It's me, thread %lu!\n", pthread_self());
while(1)
{
sleep(4);
}
pthread_exit(NULL);
}
int main(int argc, char *argv[])
{
pthread_t threads[NUM_THREADS];
int rc, t;
for(t=0;t<NUM_THREADS;t++){
printf("In main: creating thread %d\n", t);
rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
if (rc){
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
}
pthread_exit(NULL);
}
=================================
Output
In main: creating thread 0
In main: creating thread 1
Hello World! It's me, thread 2305843009225046224!
In main: creating thread 2
In main: creating thread 3
In main: creating thread 4
Hello World! It's me, thread 2305843009233434832!
Hello World! It's me, thread 2305843009241823440!
Hello World! It's me, thread 2305843009250212048!
Hello World! It's me, thread 2305843009258600656!
Thanks
Krupa
|