Yup, this is what I do (I never use osg's threadmanager to create my
threads):
class OSGThread :
public osg::ExternalThread
{
public:
typedef boost::shared_ptr<ExternalThread> Ptr;
static Ptr create(const char* szName, int uiId) {
return Ptr(osg::ExternalThread::create(szName, uiId),
boost::mem_fn(subRef));
}
}
Then somewhere in the external thread, on creation:
OSGThread::Ptr osgThread;
osgThread = OSGThread::create(m_styxThread->getName().c_str(), 0);
osgThread->initialize(m_aspect);
If you want to keep the osgThread-ptr around, it's fine. I have an
object for each thread so I have a good place to store it (I actually
use whether it's set or not to determine if it should be created.)
Not at all neat, but it's the only way I've managed this.
Best regards
/Marcus
Patrick Hartling wrote:
Last night, I ran into a rather tricky problem with OpenSG and threading. I
have a multi-threaded application where the bulk of the work is in one
thread: the frame loop. (If it makes any difference, the frame loop is not
in the primordial thread--VR Juggler is involved.) This is where
OSG::osgInit(), OSG::osgExit(), and everything in between are being called.
In extending this application, there now exists the potential for an
externally spawned thread (i.e., a thread not created by OSG::ThreadManager)
to try to access scene graph data. This fails, to the best of my
understanding, because there is no aspect for the externally spawned thread.
Do I have any OpenSG-friendly ways of dealing with this situation? The
effectiveness and simplicity of my whole plan for this software hinges on
being able to access scene graph data directly from the externally spawned
thread, so I am highly motivated to get this working [*]. From reading the
documentation, I understand that there are always two aspects created, and
that is exactly how many I need. Is there some way that I can have that
externally spawned thread hook up with the second aspect even though the
thread is not created by OpenSG?
The problem is actually a little more complicated than I have described it
because I am not sure that I have any control over the spawning of the
troublesome thread. It is happening internally within third-party software,
and I do not know yet if there are callback hooks or anything that I can do
upon creation of that thread. Hence, I could be faced with some sort of
brittle hack to make this work. If nothing else, I could set up some sort of
event notification system for communication between the externally spawned
thread and the frame loop.
-Patrick
[*] I should have known that this would happen and planned better, so I have
painted myself into a bit of a tight corner here. Certainly, I am willing to
go back to the drawing board if that is what it comes to, but the best
outcome would be as I have described it above.
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users