[Insight-users] ITK Threads with memberfunctions
Markus Weigert
m.weigert at fz-juelich.de
Thu Jun 8 11:05:37 EDT 2006
Hi Jim,
thanks for your reply.
I'm doing it now in the way, that I use a separate Thread
for the registration and one for observing the GUI with MultipleMethodExecute.
When the user clicks a cancel button, the observing thread
notices this and the IterationOberver of the optimizer will set the abort flag
on the registration.
Regards,
markus
----- Original Message -----
From: Miller, James V (GE, Research)
To: Markus Weigert ; insight-users at itk.org
Sent: Thursday, June 08, 2006 4:46 PM
Subject: RE: [Insight-users] ITK Threads with memberfunctions
Markus,
I believe you should see a single process with multiple threads. I usually look at the CPU plots for each processor to determine whether all the threads are computing.
For what you are trying to do, you probably want to use SpawnThread rather than SingleMethodExecute. SingleMethodExecute is designed to execute the same code over N threads. SingleMethodExecute actually only creates N-1 threads and uses the main thread as the Nth processing thread. So while you can use SingleMethodExecute and set the number of threads to 1, you will not actually spawn any additional threads. SpawnThread on the other hand will always spawn a new thread.
Note: the Multithreader needs to be updated such that exceptions thrown in a spawned thread are caught and propagated to the main thread. I have put this type of code into the SingleMethodExecute but I still need to update SpawnThread. If your spawned thread does not throw an exception, you should be fine.
Depending on the optimizer used, you can actually do what you want without threading. The registration framework should emit an iteration event. You can attach an observer to the iteration event. Your observer can peak at your event queue and process a few gui events. If the user pressed the button to stop the registration, you can send set the Abort flag on the registration.
Jim
-----Original Message-----
From: Markus Weigert [mailto:m.weigert at fz-juelich.de]
Sent: Thursday, June 08, 2006 6:16 AM
To: Miller, James V (GE, Research); insight-users at itk.org
Subject: Re: [Insight-users] ITK Threads with memberfunctions
Hi again,
I've done the threading now like it is done in the ImageSource class.
But what I observe when I try to execute it, is not what should happen.
I expected to see two different processes in the Task Manager (Win XP),
when I call SingleMethodExecute().
But this is not the case. I actually see two tasks of the programm, but only
a single process. I expected to have two processes, which run in parallel,
one doing registration (the one which is newly created) and the original one,
which is doing GUI staff (FLTK).
I'm doing this to be able to stop the registration process manually by observing the
optimizer.
Regards,
Markus
----- Original Message -----
From: Miller, James V (GE, Research)
To: Markus Weigert ; insight-users at itk.org
Sent: Wednesday, June 07, 2006 10:41 PM
Subject: RE: [Insight-users] ITK Threads with memberfunctions
Marcus,
The pattern I use to have the multithreader call a static function (or a standard C function) and pass the object as part of the clientdata. The static method, then casts the clientdata back to the object type and calls the member function that I wanted to call.
This is how the multithreaded filters are implemented. Take a look at ImageSource::GenerateData() and ImageSource::ThreaderCallback().
Jim
-----Original Message-----
From: insight-users-bounces+millerjv=crd.ge.com at itk.org [mailto:insight-users-bounces+millerjv=crd.ge.com at itk.org]On Behalf Of Markus Weigert
Sent: Wednesday, June 07, 2006 2:38 PM
To: insight-users at itk.org
Subject: [Insight-users] ITK Threads with memberfunctions
Dear all,
I would like to make a programm, at which I'm currenty
working, multithreaded.
As far as I know, there is a class called itkMultiThreader which
provides this functionality.
My question is, if this class can also be used to create a thread
for a memberfunction of an object, because I always receive compiler
complaints from VC6 on std_call problems when I call SetSingleMethod().
As far as I know, for example posix threads only work with C-functions.
So, is this also true for the multithreader or may the problem be different?
I think that for example, the threads from Boost library can deal with member functions,
but I would not like to use a large library only for one small feature.
Can you please give me a hint?
Regards,
Markus
PS: declaring the function as static is not possible,
because it accesses non-static members.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20060608/d7a72c30/attachment-0001.htm
More information about the Insight-users
mailing list