On Thu, 02 Oct 2008, Maurilio Longo wrote: Hi Maurilio,
> I've added this little function to my copy of vm\thread.c, I attach it here so > that Przemyslaw and/or Viktor can have a look at it and also because I'm not > at ease with branching and so I don't know where to commit this change. > -----------8<----------------- > HB_FUNC( HB_THREADID ) > { > #if defined( HB_MT_VM ) > PHB_THREADSTATE pThread = ( PHB_THREADSTATE ) hb_vmThreadState(); > if( pThread ) > hb_retnl( pThread->th_id ); > #endif > } > ----------->8----------------- Why you cannot use hb_threadSelf()? It also returns valid identifier which is compatible with values returned by hb_threadStart(). If we need yet another thread identifier then we can add it but it should give some additional information. th_id is not good choice because it's platform dependent low level value. In PTHREAD and OS2 is OS thread ID. In MS-Windows is OS handler to given thread. Farther when thread is detached then this value is cleared and can be reused for new threads in some systems. > I've added this function because I was still investigating a speed issue on my > pc and I've changed also tests\speedtst.prg so that it creates two threads > which do the work (instead of a single one). Thank you. For such tests we should add additional function to measure time consumed by single thread only. For MT performance it will be also good to run this test in many threads, f.e. each loop in separate thread to calculate also the cost of thread creation and task switching. Anyhow it does not explain why you haven't used existing thread identifiers returned by hb_threadStart() and hb_threadSelf(). If you need continouse thread IDs registered by HVM then we can add such functionality. We can use 64bit counter so we will not have to worry about repeated values. We can also add support to return OS thread ID, f.e.: hb_threadOsId(). The question is only what we need. I also suggest to use clear names. F.e.: hb_threadVMID() -> incremented by us integer number hb_threadOSID() -> OS thread ID which can be reused by some .c functions > Please note that my changes are just an ugly hack to make it work and see if > having a SMP kernel on a HT cpu gives any advantage when the work is splitted > between two cpus. > I attach the modified speedtst.prg to this message also, so that anybody can > have a look at it > Well, that said, total time went from 70 seconds to 59.9 :) > MT PIV 3.6GHZ HT, OS/2 SMP kernel > ============================================================ > 0 - total application time: 59.87 > total real time: 59.88 I expected bigger difference. I'll look at the code. maybe I'll update it to use more threads. > I,ve also noted that thread 1 has a threadid of 0 (zero) while the other > threads have the correct id, maybe this is a minor glitch to correct. Because it does not have parent thread which may need to join it. It's detached for us. Just simply th_id does not mean what you thought. best regards, Przemek _______________________________________________ Harbour mailing list Harbour@harbour-project.org http://lists.harbour-project.org/mailman/listinfo/harbour