title: Why does my c++ code which I run in a Java SWT project, is paused?
body: <p>I have a c++ project for which I wanted to have a GUI. So, I decided to write the GUI in Java using SWT. </p>
  
  <p>I'm first running Java with some inputs, then, it starts c++ project with <code>Process p = Runtime.exec(...)</code>. Every sec c++ project writes some string (path of some images) to an output file and java reads it and changes the images on the GUI accordingly. </p>
  
  <p>The strange thing is, at one point Java code continue to run but c++ code get paused. When I stop Java code by killing GUI (that doesn't stop c++ project), it continues to run. When I run java code twice, at one point both stops, and I kill one of them the other continues. </p>
  
  <p>Here is Java code that updates GUI.</p>
  
  <pre><code>public void open() throws InterruptedException {
      display = Display.getDefault();
      createContents();       
  
      shell.open();
      shell.layout();
  
      Thread updateThread = new Thread() {
          public void run() {
              while (true) {
                  try {
                      Thread.sleep(860);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
  
                  Display.getDefault().syncExec(new Runnable() {
  
                      @Override
                      public void run() {
                          System.out.println("hi " + count);
                          count++;
                          refreshPanel();
                      }
                  });
              }
          }
      };
  
      updateThread.setDaemon(true);
      updateThread.start();
  
      while (!shell.isDisposed()) {
          if (!display.readAndDispatch()) {
              display.sleep();
          }
      }
  }
  </code></pre>
  
  <p>In this code, when c++ pauses count continues to be updated so I know that java is not paused. </p>
  
  <p>It stops in different elements depending on <code>time</code> that I make java thread sleep by <code>Thread.sleep(value)</code>.</p>
  
  <p>Note that my c++ code is runs two threads each of them writes to different files and each read by Java separately (for different purposes). </p>
  
  <p><strong>EDIT</strong>: When I run c++ in visual studio, it doesn't give any error or it is not paused.</p>
  
  <p>My c++ code is basically as follows</p>
  
  <pre><code>int main(){
      string str1 = "sth1", str2 = "sth2";
  
      boost::thread bs_t = boost::thread( binary_search,str1,str2);
      boost::thread ls_t = boost::thread( linear_search,str1,str2);
  
      bs_t.join();
      ls_t.join();
  }
  
  void binary_search(string str1, string str2){
      if(some_condition)
          return;
      num_comp_bs++;
      ofstream myrec_file(project_dir+"\\bin_file.ini");
  
      boost::mutex _mtx;
      _mtx.lock();
  
      myrec_file &lt;&lt; num_comp_bs &lt;&lt; endl;
      myrec_file.close();
  
      _mtx.unlock();
  
      //here I do some I/O operations and some matrix calculations
      binary_search(str1, newstr1);
      binary_search(str1, newstr2);   
  }
  
  void linear_search(string str1, string str2){
      for(int i = 1 --&gt;n){
          ofstream myrec_file(project_dir+"\\lin_file.ini");
  
          boost::mutex _mtx;
          _mtx.lock();
          myrec_file &lt;&lt; num_element_passed &lt;&lt; endl;
          myrec_file.close();
          _mtx.unlock();
          //here I do some I/O operations and some matrix calculations
      }
  }
  </code></pre>
  
  <p>Note also that it doesn't give any error.</p>
  
  <p>Any idea what may cause c++ to be paused? <strong>Is it possible that windows is blocking c++ for some reason?</strong> </p>
  
  <p>Thanks in advance,</p>