GLUT/OpenGL with threads - Having problems

Hi folks,

I’m having a small problem with threads and GLUT/OpenGL under Linux.
I’m not really sure this is allowed or not, mayby someone can help me.

My program starts and later I decide to make a new thread. This thread
then makes all GLUT calls to create window and assign callbacks.
At various points in that threads execution, the program terminates
with an XIO error 0 (success).
Sometimes it works longer, until I press the mouse button, press a key,
or something, and sometimes just directly during initialization.

Is there anything one must do to activate the current thread as the context
or so. I’m pretty sure my main thread is not doing any X, GLUT or OpenGL

Anyone with any clue?

I do not think GLUT is supporting multiple threads. I do not see why your code should not work but it is probably better to use SDL or other some library that has multiple thread support.

what i remember is that glut has some functions to create sub-windows. This may be the way it uses threads. i don’t know very well.

Hi guys,

thanks for your support. However, the problem really was as follows.

libpthreads have something like (or exactly) _init_ctors… which
is normally run when you load a library (for global C++ objects).
Earlier versions of Xlib wasn’t compiled with threads-support, it
appears to be thread safe now. But there I picked up the reason.
errno is altered by pthreads such that each thread have a unique
Since my GLUT and OpenGL stuff was in a DSO I loaded dynamically
(a plugin) and my main application (loading the DSO) didn’t link with
pthreads. I now link with pthread and it works, it might possibly also
work if I execute the __init_ctors function of the loaded libraries.

Worth noting though, when I run my app from gdb, I see no output,
my GL-drawable remains black and graphics is drawn.

/ Patric

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.