[Insight-users] Getting the thread's ID

Aviv Hurvitz aviv.hurvitz at gmail.com
Mon Jan 29 06:40:36 EST 2007


Hi again,

Having read the code of itk::MultiThreader, I've come to the conclusion that
there is no way to know the current thread's ID using the currently provided
methods.

What I finally did was call pthread_self() to get the system-dependent
thread ID. This is somewhat inelegant since the itk::MultiThreader is
supposed to encapsulate the system-dependent thread IDs and present a facade
with its own system-independent thread IDs. Using the MultiThreader to get
this nice ID isn't very practical for me, however, since the MultiThreader
object that's executing my Transfrom isn't in scope at the point where I
need the thread ID.

Here's a final thought. It might be beneficial to model ITK's threading
facade after pthreads in the following ways:
1. make the thread IDs globally unique. right now the thread IDs of
different MultiThreaders can clash
2. make a static class method in MultiThreader that returns the current
thread's ID
3. make the various functions that control threads (TerminateThread(), etc.)
be static class functions as well. 
In short - no more MultiThreader objects, just global functions.

I realize this isn't a serious suggestion, since I haven't considered how
these changes would fit in with the current uses of MultiThreaders in ITK.
Just an idea, in case the threading mechanism is ever reassessed.

Kind regards,

- Aviv



Luis Ibanez wrote:
> 
> 
> HI Aviv,
> 
> 
> Please read the Multi-Threading Tutorial from the ITK Advanced course:
> 
>   http://www.na-mic.org/Wiki/images/2/24/Insight-MultiThreading.ppt
> 
> It should answer your questions regarding the use of
> the itk::MultiThreader class.
> 
> 
> 
>     Regards,
> 
> 
> 
>        Luis
> 
> 
> 
> --------------------------
> Aviv Hurvitz wrote:
>> Hi all,
>> 
>> I wrote a Transform class that's doing a large calculation in 
>> Transform::TransformPoint().
>> I want to cache the values in the calculation. The problem is, this 
>> transform is shared by multiple threads. So I want to save the cached 
>> value in several instances, one for each thread.
>> 
>> If I had the thread's id, I could do this association. Is there any way 
>> to get the currently running thread's ID?
>> 
>> Thanks.
>> 
>> - Aviv
>> 
>> 
>> ------------------------------------------------------------------------
>> 
>> _______________________________________________
>> Insight-users mailing list
>> Insight-users at itk.org
>> http://www.itk.org/mailman/listinfo/insight-users
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 
> 

-- 
View this message in context: http://www.nabble.com/Getting-the-thread%27s-ID-tf3058855.html#a8687941
Sent from the ITK - Users mailing list archive at Nabble.com.



More information about the Insight-users mailing list