[vtk-developers] vtkMultiThreader Class Error in Output

Berk Geveci berk.geveci at kitware.com
Sun Oct 12 09:13:21 EDT 2014


Check out the documentation of SetSingleMethod(), which reads:

> Set the SingleMethod to f() and the UserData field of the ThreadInfo that
is passed to it will be data.
> This method (and all the methods passed to SetMultipleMethod) must be of
type
> vtkThreadFunctionType and must take a single argument of type void *.

The argument passed to SetSingleMethod() is wrapped by the ThreadInfo
struct and passed to the method. Something like:

cout <<  ((vtkMultiThreader::ThreadInfo*)data)->UserData << endl

should do the trick. Also see:

http://www.vtk.org/doc/nightly/html/classvtkMultiThreader_1_1ThreadInfo.html

Best,
-berk

On Sun, Oct 12, 2014 at 5:11 AM, Jatin Parekh <jatinparekh93 at gmail.com>
wrote:

> Hi!
> I have a simple code as shown below. I am passing the same parameter to a
> function via a normal function call and another via the vtkMultiThreader
> SpawnThread. However, I am unable to get the expected output.
>
> *#include <iostream>*
>
> *#include <vtkMultiThreader.h>*
>
> *void *ThreadedFunction(void *data)*
>
> *{*
>
> *    std::cout << data << std::endl;*
>
> *}*
>
> *int main()*
>
> *{*
>
> *    vtkMultiThreader *threaded = vtkMultiThreader::New();*
>
> *    void *x = (void *)1;*
>
>
>  *    std::cout << "Non Threaded function call:" << std::endl;*
>
> *    ThreadedFunction(x);*
>
>
>  *    std::cout << "Now in threads:" << std::endl;*
>
> *    threaded->SpawnThread(ThreadedFunction, x);*
>
> *    return 0;*
>
> *}*
>
>
> If I understand correctly, the output for both, the threaded function call as well as non threaded function call should be the same.
>
> But it gives me the following output:
>
> *Non Threaded function call:*
>
> *0x1*
>
> *Now in threads:*
>
> *0x10a89d0*
>
>
> SO, the non-threaded function call displays the correct value whereas the MultiThreader call displays some different value.
>
> I don't get the reason why the 2 function calls give different outputs. Are they supposed to be different? If yes, then can someone please explain why it is supposed to be so?
>
> If no, then any ideas/hints on where I could possibly be making an error?
>
>
> Thanks!
>
> Jatin Parekh
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtk-developers
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20141012/d67ad0ac/attachment-0002.html>


More information about the vtk-developers mailing list