title: Multithreading is slowing down OpenGl loop
body: <p>I'm currently programing a minecraft like map generator using OpenGL in C++. I have a AMD Rayzen 5 3600 6-Core.</p>
  <p>So, when I tried to add multithreading in my main loop to call my chunks generation, it was slowing down the rendering. <strong>I'm not using multithreading for rendering</strong>.</p>
  <p>I'm on Windows using MinGw to compile code and multithreading works on posix.</p>
  <p>The problem is I can't figure why it makes my rendering slow. Even if I try to create <strong>ONLY ONE</strong> thread I loose FPS. And even if I create a thread to do simple task like :</p>
  <p><code>std::cout &lt;&lt; &quot;Thread #&quot; &lt;&lt; i &lt;&lt; &quot;\n&quot;;</code></p>
  <p>It will slow down the rendering.</p>
  <p>My compile flags are <code>-pthread -lopengl32 -lglu32 -lgdi32 -luser32 -lkernel32 -lglfw3dll -O3</code></p>
  <p>I'm adding the fact that at school I'm working on MacOS and the multithreading is not slowing down the rendering. I'm assuming a MinGW problem.</p>
  <p>If you have any kind of idea to help me I will take it. Thank you for your forthcoming  responses !</p>
  <p>There is my loop :</p>
  <pre><code>while (!glfwWindowShouldClose(window))
      {
          Frustum frustum;
          //fps(window);
          float currentFrame = glfwGetTime();
          deltaTime = currentFrame - lastFrame;
          lastFrame = currentFrame;
  
          processInput(window);
  
          glClearColor(0.69f, 0.94f, 0.95f, 1.0f);
          glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
          shader.use();
          glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 1000.0f);
          shader.setMat4(&quot;projection&quot;, projection);
          glm::mat4 view = camera.GetViewMatrix();
          shader.setMat4(&quot;view&quot;, view);
          frustum.Transform(projection, view);
          shader.setVec3(&quot;lightPos&quot;, glm::vec3(0.7, 0.2, 0.5));
          shader.setVec3(&quot;viewPos&quot;, camera.Position);
          displayChunk(shader, vox, &amp;chunks, frustum);
  
          glDepthFunc(GL_LEQUAL); // change depth function so depth test passes when values are equal to depth buffer's content
          skyboxShader.use();
          view = glm::mat4(glm::mat3(camera.GetViewMatrix())); // remove translation from the view matrix
          skyboxShader.setMat4(&quot;view&quot;, view);
          skyboxShader.setMat4(&quot;projection&quot;, projection);
          // skybox cube
          glBindVertexArray(skybox.skyboxVAO);
          glActiveTexture(GL_TEXTURE0);
          glBindTexture(GL_TEXTURE_CUBE_MAP, skybox.cubemapTexture);
          glDrawArrays(GL_TRIANGLES, 0, 36);
          glBindVertexArray(0);
          glDepthFunc(GL_LESS); // set depth function back to default
  
          glfwSwapBuffers(window);
          glfwPollEvents();
          
          for (unsigned i = 0; i &lt; 1; ++i)
          {
              threads[i] = std::thread([&amp;mtx, i]
                                       {
                                           {
                                               // Use a lexical scope and lock_guard to safely lock the mutex only for
                                               // the duration of std::cout usage.
                                               std::lock_guard&lt;std::mutex&gt; iolock(mtx);
                                               std::cout &lt;&lt; &quot;Thread #&quot; &lt;&lt; i &lt;&lt; &quot; is running\n&quot;;
                                           }
                                       });
          }
  
          for (auto &amp;t : threads)
          {
              t.join();
          }
      }
  </code></pre>