title: Qt C++ read access violation Exception
body: <p>I am working with a project with Qt and C++, and project uses multiple thread and extern global variable. The extern variable is accessing from different thread for reading and writing, where as there is no mutex implemented currently to read/write these variable.   Right now I am getting some exception while running the program and this is not happening every time but randomly. </p>
  
  <p>These are some output from Qtcreator</p>
  
  <pre><code>Invalid address specified to RtlValidateHeap( 000000778A310000, 000000778E6AF5D0 )
  Debug Assertion Failed!
  
  Program: ...AppStore-MSVC_X64\debug\App.exe
  File: f:\dd\vctools\crt\crtw32\misc\dbgheap.c
  Line: 1322
  
  Expression: _CrtIsValidHeapPointer(pUserData)
  
  For information on how your program can cause an assertion
  failure, see the Visual C++ documentation on asserts.
  
  (Press Retry to debug the application)
  Debug Assertion Failed!
  
  
  Program: ...AppStore-MSVC_X64\debug\App.exe
  File: f:\dd\vctools\crt\crtw32\misc\dbgheap.c
  Line: 1328
  
  Expression: _BLOCK_TYPE_IS_VALID(pHead-&gt;nBlockUse)
  
  For information on how your program can cause an assertion
  failure, see the Visual C++ documentation on asserts. 
  </code></pre>
  
  <p>Here is the screenshot after exception. </p>
  
  <p><a href="https://i.stack.imgur.com/tIGHh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tIGHh.png" alt="enter image description here"></a></p>
  
  <ol>
  <li>Is this happening because the extern variable are not thread safe?</li>
  <li>Or due to variable uninitialized, but while debugging I can see the variable has some data.  </li>
  </ol>
  
  <h1>Edit</h1>
  
  <p>I cannot post the entire code here as the project contain lot of source code, but the situation is something like</p>
  
  <p><strong>global.h</strong></p>
  
  <pre><code>extern QString outfilepath;
  </code></pre>
  
  <p><strong>main.cpp</strong></p>
  
  <pre><code> QString outfilepath;
   ...................
   ...................
   outfilepath = somePath;
  </code></pre>
  
  <p><strong>thread1.cpp</strong></p>
  
  <pre><code> ...................
   QString tmp1 = outfilepath;
   ...................
  </code></pre>
  
  <p><strong>thread2.cpp</strong></p>
  
  <pre><code> ...................
   QString tmp2 = outfilepath;
   ...................
  </code></pre>