How to get rid of "glutInit being called a second"

I uses pthread_create(&THREAD_ID,NULL, startDisplay, NULL) to create a thread for running my OpenGL where startDisplay() is a function that calls glutInit(), glutCreateWindow etc.

When I kill my thread by calling pthread_cancel(THREAD_ID) and call pthread_create((&THREAD_ID,NULL, startDisplay, NULL) again, glutInit() gave me “GLUT: Warning in EXEC: glutInit being called a second time”.

I searched the glutInit.cpp and found the following code:

void glutInit(int *argcp, char **argv) {
char *str, *geometry = NULL;
int i;

if (gState.display) {
__glutWarning(“glutInit being called a second time.”);

Is there anyway that I can set gStat.display to false in our application when I re-create the pthread? If yes, how to do it?

Basically, I am asking how to get rid of “glutInit being called a second time.” so that I can bring up a new thread to run my OpenGL window again?

Thanks a lot for your help in advance !!!


i might be wrong, but glutInit might be there to just initialize the glut data structures, collect some system data and such, try calling it only once in the beginning of the program and see what happens, or maybe trow in a if statement that only executes it the first time.