Multi-threaded GL Crash

I have the following application that attempts to perform multi-threaded rendering inside a glut application. Any ideas on why this crashes?



#include <X11/Xlib.h>  // for XInitThreads() call
#include <GL/glut.h> // GL Utility Toolkit
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>

boost::mutex gdmutex;

void display(void)
{
    boost::mutex::scoped_lock lock(gdmutex);
   
    glClear(GL_COLOR_BUFFER_BIT); 
    glutSolidTetrahedron();
    glutSwapBuffers();
}

void render(void)
{
    while(true) { display(); }
}

void visible(int state)
{
    static bool once(false);
    
    if(!once) { boost::thread rthread(&render); }
    
    once = true;
}

int main(int argc, char* argv[])
{
    XInitThreads();
    
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE);
    glutCreateWindow("Sample");
    
    glutDisplayFunc(display);
    glutVisibilityFunc(visible);
    
    glutMainLoop();

    return 0;
}

Is there a makeCurrent concept in GLUT? That is the only thing I notice.

All GL commands have to be issued within the thread that hold the GL context current. With other words, you can’t split GL commands across different threads. With even other words, you have to use the default thread (the thread that initialized and created your glut window) as your rendering thread.

No. GLUT is a beginner’s tool, it shouldn’t be used for anything relatively advanced.