Continous thread ids
sapdb at komadev.de
kai at freshx.de
Wed Nov 26 16:26:44 PST 2003
Hi,
i wrote a little thread test programm. when i run it i get an output like
...
10 of 10 threads running, i am 0x8069000
10 of 10 threads running, i am 0x806c000
10 of 10 threads running, i am 0x806f000
...
is there a generic way (not kse dependant), to get a still unique countinous
thread id starting with 1,2 .... n ? With linuxthreads, it was possible by a
dirty hack, masking out the upper 20 bit, but that seems not to be the way its
meant to work huh ?
any ideas ?
kind regards kai
------------------------------------------------------------
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#define MAXTHREADS 10
int i;
void *threadedCounter(void *x)
{
for(int a=0;a<10;a++){
printf("%d of %d threads running, i am 0x%x\n",i,MAXTHREADS,pthread_self
());
sleep(2);
}
return NULL;
}
int main(void)
{
pthread *t;
for(i = 0 ; i < MAXTHREADS ; i++)
pthread_create(&t,NULL,threadedCounter,NULL);
sleep(MAXTHREADS*3+2);
return 0;
}
More information about the freebsd-threads
mailing list