[vtk-developers] vtkMultiThreader Class Error in Output

Jatin Parekh jatinparekh93 at gmail.com
Sun Oct 12 05:11:46 EDT 2014


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20141012/79afa9d0/attachment-0002.html>


More information about the vtk-developers mailing list