Date: Thu, 27 Nov 2003 01:26:29 +0100 From: "sapdb@komadev.de" <kai@freshx.de> To: freebsd-threads@freebsd.org Subject: Continous thread ids Message-ID: <1069892789.3fc544b58a2d7@localhost>
next in thread | raw e-mail | index | archive | help
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; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1069892789.3fc544b58a2d7>