On Fri, 26 Mar 2010, Maurilio Longo wrote: Hi,
> if we have a thread object and/or a thread local storage area we could call > _gettid() on thread start and save this value which never changes during > thread life. > This saves us a Dos... call every time we need the thread id. > Does this make sense? Yes and I thought about it. Anyhow because we may want to make some Harbour VM functions available for non HVM threads then we should have code which will make such TLS initialization online if necesary, i.e. current _hb_gettid(): ULONG _hb_gettid( void ) { ULONG tid = 0; PTIB ptib = NULL; if( DosGetInfoBlocks( &ptib, NULL ) == NO_ERROR ) tid = ptib->tib_ptib2->tib2_ultid; return tid; } should be replaced by sth like: ULONG _hb_gettid( void ) { static PULONG s_pThID = NULL; if( !s_pThID ) { DosAllocThreadLocalMemory( 1, &s_pThID ); *s_pThID = 0; } if( ! *s_pThID ) { PTIB ptib = NULL; if( DosGetInfoBlocks( &ptib, NULL ) == NO_ERROR ) *s_pThID = ptib->tib_ptib2->tib2_ultid; } return *s_pThID; } But before I'll make any modifications in core code I would like to see real test results. It's possible that DosAllocThreadLocalMemory() is already highly optimized by compiler. Can you check the performance of above functions in some simple loop? > PS. We could also have space for user/cpu times in that area so that we can > write there on thread end and they would be available even after thread end > when the Dos... api call cannot find the thread id anymore. When threads ends then it's TLS area is freed so such information will be lost in a while. Anyhow we can try to add the terminated thread time to some normal global variable and then use this value in some special functions returning total CPU time consumed by application. Still not perfect because it will not count running thread time but for tests like speedtst.prg should be enough. Anyhow here we may also want to make different modification and if possible introduce code which will count total thread time only like in OS2 also for other platforms and the update speedtst to use it. The final results of './speedtst --thread' will be much more clear in such version. best regards, Przemek _______________________________________________ Harbour mailing list (attachment size limit: 40KB) Harbour@harbour-project.org http://lists.harbour-project.org/mailman/listinfo/harbour