Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Which function do you intend to be "thread-safe"? </p> <p>I think that the term should be applied to your CommonFunction. This is a function that you intend to be called be several (two in this first case) threads.</p> <p>I think your code has a rule on the lines of:</p> <pre><code>Thread 2 do some work meanwhile Thread 3 wait until Thread 2 finishes then you do some work </code></pre> <p>In fact your code has</p> <pre><code>WaitForSingleObject(pthis-&gt;thread3-&gt;m_hThread,INFINITE); </code></pre> <p>maybe waits for the wrong thread?</p> <p>But back to thread safety. Where is the policing of the safety? It's in the control logic of your threads. Suppose you had lots of threads, how would you extend what you've written? You have lots of logic of the kind:</p> <pre><code>if thread a has finished and thread b has finished ... </code></pre> <p>Really hard to get right and maintain. Instead you need to make CommonFunction truly thread safe, that is it needs to tolerate being called by several threads at the same time.</p> <p>In this case you might do that by putting some kind of mutex around the critical part of the code, which perhaps in this case is the whole function - it's not clear whether you intend to keep the items you copy together or whether you mind if the values are interleaved.</p> <p>In the latter case the only question is whether access to myArray and myShiftArray are thread safe collections </p> <pre><code> temp = myArray.GetAt(i); myShiftArray.Add(temp); </code></pre> <p>all your other variables are local, on the stack so owned by current threads - so you just need to consult the documentation for those collections to determine if they can safely be called by separate threads.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload