title: Qt application crashes when making 2 network requests from 2 threads
body: <p>I have a Qt application that launches two threads from the main thread at start up. Both these threads make network requests using distinct instances of the QNetworkAccessManager object. My program keeps crashing about 50% of the times and I'm not sure which thread is crashing.</p>
  
  <p>There is no data sharing or signalling occurring directly between the two threads. When a certain event occurs, one the threads signals the main thread, which may in turn signal the second thread. However, by printing logs, I am pretty certain the crash doesn't occur during the signalling.</p>
  
  <p>The structure of both threads is as follows. There's hardly any difference between the threads except for the URL etc.</p>
  
  <pre><code>MyThread() : QThread() {
      moveToThread(this);
  }
  
  MyThread()::~MyThread() {
      delete m_manager;
      delete m_request;
  }
  
  MyThread::run() {
      m_manager = new QNetworkAccessManager();
      m_request = new QNetworkRequest(QUrl("..."));
  
      makeRequest();
      exec();
  }
  
  MyThread::makeRequest() {
      m_reply = m_manager-&gt;get(*m_request);
      connect(m_reply, SIGNAL(finished()), this, SLOT(processReply()));
      // my log line
  }
  
  MyThread::processReply() {
      if (!m_reply-&gt;error()) {
          QString data = QString(m_reply-&gt;readAll());
          emit signalToMainThread(data);
      }
      m_reply-&gt;deleteLater();
      exit(0);
  }
  </code></pre>
  
  <p>Now the weird thing is that if I don't start one of the threads, the program runs fine, or at least doesn't crash in around 20 invocations. If both threads run one after the other, the program doesn't crash. The program only crashes about <strong><em>half the times</em></strong> if I start and run both the threads concurrently.</p>
  
  <p>Another interesting thing I gathered from logs is that whenever the program crashes, the line labelled with the comment <code>my log line</code> is the last to be executed by both the threads. So I don't know which thread causes the crash. But it leads me to suspect that QNetworkAccessManager is somehow to blame.</p>
  
  <p>I'm pretty blank about what's causing the crash. I will appreciate any suggestions or pointers. Thanks in advance.</p>