On Tue, 11 Nov 2008, David Arturo Macias Corona wrote: Hi David,
> Do you have answer about this ? But was it the question? > I do not know if it is what you are looking for > I found in different places of documentation included in OW > --------- > The macro _threadid can be used to determine the current thread > identifier. > --------- > The _threadid macro can be used to determine the current thread > identifier. It is defined as follows. > int *__threadid(void); > #define _threadid (__threadid()) > The header file stddef.h contains the definition of the _threadid macro. > --------- > _threadid > Prototype in <stddef.h>. > > This variable/function may be used to obtain the id of the current > thread which is an int. In the 32-bit libraries, _threadid is a > function that returns a pointer to an int. In the 16-bit libraries, > _threadid is a far pointer to an int. Note that the value stored where > _threadid points does not necessarily change when a thread context > switch occurs (so do not make a copy of the pointer ... it may change). > To obtain the current thread identifier, simply code: > int tid = *_threadid; > ------------- > So I tried in source\vm\thread.c > --------------- > #if defined( HB_OS_OS2 ) > #include <stddef.h> <---- David was here ! > ULONG _hb_gettid( void ) > { > ULONG tid = 0; > PTIB ptib = NULL; > > printf( "_hb_gettid()\r\n", tid ); fflush(stdout); > /* <---- David was here ! > if( DosGetInfoBlocks( &ptib, NULL ) == NO_ERROR ) > { > if( ! ptib ) > { printf( "ptib is NULL\r\n" ); fflush(stdout); } > else if( !ptib->tib_ptib2 ) > { printf( "ptib->tib_ptib2 is NULL\r\n" ); fflush(stdout); } > else > tid = ptib->tib_ptib2->tib2_ultid; > } > */ > > tid = *_threadid; <---- David was here ! > > printf( "TID=%lu\r\n", tid ); fflush(stdout); > > return tid; > } > #endif > --------------- > and mttest02.exe result with values TID=1, 2 > --------------- > [...] > _hb_gettid() > TID=1 > 1. hb_threadMutexLock() > _hb_gettid() > TID=2 > [...] > --------------- > So if _threadid is useful giving same value as GCC _gettid(), then > _hb_gettid() can be discarded and use in harbour\include\hbthread.h: Yes, thanks for information. We can use it but it will not change too much for us with the exception that it will force using _beginthread() because __threadid() in OW returns pointer to member of structure initialized inside _beginthread(). I was asking about OS2 API call to not introduce such dependencies. > # if defined( __GNUC__ ) > # define HB_THREAD_SELF() ( ( TID ) _gettid() ) > # else > // case for OpenWatcom > // Use something like > #include <stddef.h> <---- David was here ! > tid = *_threadid; <---- David was here ! > int vs ULONG ? > In the 32-bit libraries, _threadid is a function that returns a pointer > to an int > # else > //discard > # define HB_THREAD_SELF() ( ( TID ) _hb_gettid() ) > # endif > ----------- > And in this case ( thread ID ) what is happening/using in Windows > OpenWatcom ? It can be used in OS/2 Watcom ? Yes. If you want to use it it's enough to make: # if defined( __GNUC__ ) # define HB_THREAD_SELF() ( ( TID ) _gettid() ) # elif defined( __WATCOMC__ ) # define HB_THREAD_SELF() ( ( TID ) ( * _threadid ) ) # else # define HB_THREAD_SELF() ( ( TID ) _hb_gettid() ) # endif I do not know the cost of calling DosGetInfoBlocks() in OS2. It's highly possible that using OW _threadid will be much more faster. In such case we should commit above modification. Anyhow we should also keep _hb_gettid() because it may be usable in the future if we will want to eliminate CRTL in thread API. best regards, Przemek _______________________________________________ Harbour mailing list Harbour@harbour-project.org http://lists.harbour-project.org/mailman/listinfo/harbour