|Project:||The Open Toolkit library|
OpenTK calls XInitThreads (at least) at two places:
1. ctor of OpenTK.Platform.X11.X11Factory
2. static ctor of OpenTK.Platform.X11.API
From the man page of XInitThreads:
"The XInitThreads() function initializes Xlib support for concurrent threads. This function must be the first Xlib function a multi-threaded program calls, and it must complete before any other Xlib call is made."
So the current situation is bad for two reasons.
1. XInitThreads is called twice (could be fixed easily)
2. XInitThreads might not be the first XLib call.
The second point is really the main problem here. I stubled upon this issue when writing a GTK# app that uses GLWidget to display an opengl window. GLWidget uses OpenTK to create an opengl context. Before GLWidget get's initialized and displayed a lot of XLib calls happen because this is a GTK application! In the end when GLWidget is initialized and shown OpenTK does it's XInitThreads calls.
While the program ran fine on my desktop pc is crashed in many interesting ways on my notebook. When commenting out the XInitThreads calls in OpenTK the program ran smoothly.
The only solution I can think of is removing the unconditional XInitThreads calls from OpenTK and let the user decide whether it needs multithreaded X11 or not.