XInitThreads - where

I need to call XInitThreads in my app. I think it’s meant to go before any x server calls. Is the initialize method of my application class early enough? Can I be sure that the juce headers won’t so anything?

Bruce

The initialise method will probably happen after the juce stuff inits, but you could put it in you application object’s constructor.

Should I be calling it too? What’s it for?

It make xlib threadsafe. I need to use it - I think, so that I can use xlib display connections across threads.

You may have never hit it since juce does all it’s drawing on the message thread. Once you start using different threads - OpenGL, of course - then you need to share the display connection a bit, so that contexts can be reused a bit, but protect against multiple thread access.

Here’s the competition’s take: :wink:

http://doc.trolltech.com/qq/qq06-glimpsing.html

So maybe it should be a compile flag like shared memory? That would be cool. As you can tell though, I haven’t fully tested it. Here’s a few other references:

http://www.equalizergraphics.com/documentation/parallelOpenGLFAQ.html

http://www.mail-archive.com/devel@xfree86.org/msg06129.html

Bruce

Well I don’t see anything wrong with adding it to the library - I’d suggest that it goes in juce_linux_Messaging.cpp:

[code]void MessageManager::doPlatformSpecificInitialisation()
{
XInitThreads();

[/code]

I went to put it in, but it seems to be there already :? Line 183 or so does it. I suppose possibly the XSetIOHandler should be after it?

Some of the crashes I’ve been seeing match descriptions of X threading, but maybe that wasn’t my quick-fix.

I’ll let you know if I do find anything that should be different.

Bruce

Drat! Looks like I beat myself to it! But yes, it should probably be at the start of the function instead.

Looks like it’s not as simple as the docs imply. In this thread - featuring a familiar name, it mentions that only certain Xlib calls are protected.

http://www.renoise.com/board/index.php?showtopic=15520

This one is more blunt:

http://lists.freedesktop.org/archives/xorg/2006-February/012908.html

The problem is that I still get sigsegv in juce code after I start doing stuff in threads - seems to be when juce accesses the connection I’m ‘sharing’.
:cry:

I’m going to try making a display connection per thread and see what I get, unless anyone has any insight?

Bruce