I am not asking about parallelization of physics and so on stuff with parallel_for() like stuff.

I've managed to have separate rendering thread from logic thread, in glfw3 application:

void render_thread() {
    while( !glfwWindowShouldClose(win) ) {
        sleep(10); // emulate heavy rendering, to be sure that main loop stops event processing during this sleep
        glfwSetWindowTitle(win, "some title"); // posts message? to window queue to update title

And init/event/input handling loop is as follows:

void main_thread() {
    set_thread_priority(highest); // to be sure this is first priority in OS sheduler, compared to render thread
    win = glfwCreateWindow(...);
    std::thread rt(&render_thread);
    while (!glfwWindowShouldClose(_glWindow))
        glfwWaitEvents(); // could put thread to sleep

Here is the problem, when i click to close window:

  • rt.join() never returns, because it waits for render_thread() to return
  • render_thread() could not return from glfwSetWindowTitle() call, seems no message processing goes on, or something other that i dont know.

Maybe my whole approach is wrong, but how should i solve that in a sane way?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.