From owner-freebsd-threads@FreeBSD.ORG Wed Nov 26 17:13:35 2003 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9CD8D16A4CE for ; Wed, 26 Nov 2003 17:13:35 -0800 (PST) Received: from exchhz01.viatech.com.cn (ip-167-164-97-218.anlai.com [218.97.164.167]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6D3CA43F3F for ; Wed, 26 Nov 2003 17:13:26 -0800 (PST) (envelope-from davidxu@viatech.com.cn) Received: from viatech.com.cn (ip-240-1-168-192.rev.dyxnet.com [192.168.1.240]) by exchhz01.viatech.com.cn with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2650.21) id WZMFXXV3; Thu, 27 Nov 2003 08:52:25 +0800 Message-ID: <3FC55112.2010800@viatech.com.cn> Date: Thu, 27 Nov 2003 09:19:14 +0800 From: David Xu User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.5b) Gecko/20030723 Thunderbird/0.1 X-Accept-Language: en-us, en MIME-Version: 1.0 To: "sapdb@komadev.de" References: <1069892789.3fc544b58a2d7@localhost> In-Reply-To: <1069892789.3fc544b58a2d7@localhost> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit cc: freebsd-threads@freebsd.org Subject: Re: Continous thread ids X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Nov 2003 01:13:35 -0000 sapdb@komadev.de wrote: >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 ? > > It won't work, the thread pointer is the address returned by malloc() which is out of control of thread library, the reason you get consecutive numbers is because you don't intermediately call malloc() when creating threads, in real world, you won't get this consecutive numbers. libkse has unique thread id for each thread, but it seems there isn't any API exports this unique id. >kind regards kai > >------------------------------------------------------------ >#include >#include >#include > >#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; >} > David Xu