<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><p style="margin:0px"><span style="font-family:monospace;font-size:9pt;color:rgb(49,55,57)">Jatin Parekh</span></p></pre></div></div></div>