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;
}