<div dir="ltr">Hi Berk,<div>That worked.</div><div>Thanks for your quick reply!</div><div><br></div><div>Jatin Parekh</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Oct 12, 2014 at 6:43 PM, Berk Geveci <span dir="ltr"><<a href="mailto:berk.geveci@kitware.com" target="_blank">berk.geveci@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Check out the documentation of SetSingleMethod(), which reads:<div><br></div><div>> Set the SingleMethod to f() and the UserData field of the ThreadInfo that is passed to it will be data. </div><div>> This method (and all the methods passed to SetMultipleMethod) must be of type </div><div>> vtkThreadFunctionType and must take a single argument of type void *.<br></div><div><br></div><div>The argument passed to SetSingleMethod() is wrapped by the ThreadInfo struct and passed to the method. Something like:</div><div><br></div><div>cout <<  ((vtkMultiThreader::ThreadInfo*)data)->UserData << endl</div><div><br></div><div>should do the trick. Also see:</div><div><br></div><div><a href="http://www.vtk.org/doc/nightly/html/classvtkMultiThreader_1_1ThreadInfo.html" target="_blank">http://www.vtk.org/doc/nightly/html/classvtkMultiThreader_1_1ThreadInfo.html</a><br></div><div><br></div><div>Best,</div><div>-berk</div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Sun, Oct 12, 2014 at 5:11 AM, Jatin Parekh <span dir="ltr"><<a href="mailto:jatinparekh93@gmail.com" target="_blank">jatinparekh93@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div>Hi!</div>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.<div><br><div>
<pre style="margin-top:0px;margin-bottom:0px"><i><span style="color:rgb(0,0,128)">#include</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)"><iostream></span></i></pre>
<pre style="margin-top:0px;margin-bottom:0px"><i><span style="color:rgb(0,0,128)">#include</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)"><vtkMultiThreader.h></span></i></pre>
<pre style="margin-top:0px;margin-bottom:0px"><i style="font-family:arial"><span style="color:rgb(128,128,0)">void</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(0,0,0)">ThreadedFunction</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(128,128,0)">void</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(0,0,0)">data</span><span style="color:rgb(0,0,0)">)</span></i><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,0)"><i>{</i></span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><i><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(128,0,128)">std</span><span style="color:rgb(0,0,0)">::</span>cout<span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)"><<</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">data</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)"><<</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">std</span><span style="color:rgb(0,0,0)">::</span>endl<span style="color:rgb(0,0,0)">;</span></i></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,0)"><i>}</i></span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><i><span style="color:rgb(128,128,0)">int</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">main</span><span style="color:rgb(0,0,0)">()</span></i></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,0)"><i>{</i></span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><i><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(128,0,128)">vtkMultiThreader</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(0,0,0)">threaded</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">vtkMultiThreader</span><span style="color:rgb(0,0,0)">::</span><span style="color:rgb(0,0,0)">New</span><span style="color:rgb(0,0,0)">();</span></i></pre>
<pre style="margin-top:0px;margin-bottom:0px"><i><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(128,128,0)">void</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(0,0,0)">x</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(128,128,0)">void</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*)</span><span style="color:rgb(0,0,128)">1</span><span style="color:rgb(0,0,0)">;</span></i></pre>
<pre style="margin-top:0px;margin-bottom:0px"><i><br></i></pre>
<pre style="margin-top:0px;margin-bottom:0px"><i><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(128,0,128)">std</span><span style="color:rgb(0,0,0)">::</span>cout<span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)"><<</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"Non</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">Threaded</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">function</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">call:"</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)"><<</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">std</span><span style="color:rgb(0,0,0)">::</span>endl<span style="color:rgb(0,0,0)">;</span></i></pre>
<pre style="margin-top:0px;margin-bottom:0px"><i><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(0,0,0)">ThreadedFunction</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">x</span><span style="color:rgb(0,0,0)">);</span></i></pre>
<pre style="margin-top:0px;margin-bottom:0px"><i><br></i></pre>
<pre style="margin-top:0px;margin-bottom:0px"><i><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(128,0,128)">std</span><span style="color:rgb(0,0,0)">::</span>cout<span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)"><<</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"Now</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">in</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">threads:"</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)"><<</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">std</span><span style="color:rgb(0,0,0)">::</span>endl<span style="color:rgb(0,0,0)">;</span></i></pre>
<pre style="margin-top:0px;margin-bottom:0px"><i><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(0,0,0)">threaded</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(0,0,0)">SpawnThread</span><span style="color:rgb(0,0,0)">(</span>ThreadedFunction<span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">x</span><span style="color:rgb(0,0,0)">);</span></i></pre>
<pre style="margin-top:0px;margin-bottom:0px"><i><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(128,128,0)">return</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">0</span><span style="color:rgb(0,0,0)">;</span></i></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,0)"><i>}</i></span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px">If I understand correctly, the output for both, the threaded function call as well as non threaded function call should be the same.</pre><pre style="margin-top:0px;margin-bottom:0px">But it gives me the following output:</pre><pre style="margin-top:0px;margin-bottom:0px"><p style="margin:0px"><span style="font-family:monospace;font-size:9pt;color:rgb(49,55,57)"><i>Non Threaded function call:</i></span></p><p style="margin:0px"><span style="font-family:monospace;font-size:9pt;color:rgb(49,55,57)"><i>0x1</i></span></p><p style="margin:0px"><span style="font-family:monospace;font-size:9pt;color:rgb(49,55,57)"><i>Now in threads:</i></span></p><p style="margin:0px"><span style="font-family:monospace;font-size:9pt;color:rgb(49,55,57)"><i>0x10a89d0</i></span></p><p style="margin:0px"><span style="font-family:monospace;font-size:9pt;color:rgb(49,55,57)"><br></span></p><p style="margin:0px"><span style="font-family:monospace;font-size:9pt;color:rgb(49,55,57)">SO, the non-threaded function call displays the correct value whereas the MultiThreader call displays some different value.</span></p><p style="margin:0px"><span style="font-family:monospace;font-size:9pt;color:rgb(49,55,57)">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?</span></p><p style="margin:0px"><span style="font-family:monospace;font-size:9pt;color:rgb(49,55,57)">If no, then any ideas/hints on where I could possibly be making an error?</span></p><p style="margin:0px"><span style="font-family:monospace;font-size:9pt;color:rgb(49,55,57)"><br></span></p><p style="margin:0px"><span style="font-family:monospace;font-size:9pt;color:rgb(49,55,57)">Thanks!</span></p><span><font color="#888888"><p style="margin:0px"><span style="font-family:monospace;font-size:9pt;color:rgb(49,55,57)">Jatin Parekh</span></p></font></span></pre></div></div></div>
<br></div></div>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/vtk-developers" target="_blank">http://public.kitware.com/mailman/listinfo/vtk-developers</a><br>
<br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>