Hello Weiyu,

Weiyu Yi wrote:
> I have some problems when I add some multithreading functionality to a 
> project.
> 
> ******************************************************************************************************
>  
> 
> First I think I should describe the project a bit:
[SNIP - project description]

thanks for providing the background info.

> ******************************************************************************************************
> Now is my error:
> 
> By single-thread there is no error, but my multithreading, this means 2 
> threads, one is for collision detection and the other is the movem, the 
> user phase application.
> 
> Errors like this:
> =========================================
> Program received signal SIGSEGV, Segmentation fault.
> [Switching to Thread 0xb4d9eb90 (LWP 18751)]
> 0xb72f7cd5 in osg::PThreadBase::getAspect () at 
> /home/weiyu/Projects/OpenSG/Source/System/FieldContainer/OSGThread.cpp:142
> 142        return *pUint;

it looks like you are accessing OpenSG objects from a thread OpenSG does 
not know anything about. see below for more details.

> =========================================
> I imagine that, there are 2 probabilities for the errors?
> 
> 1: the the opensg's function is called in the scope of callback(), which 
> is called by the thread collision detection not the movem, although it's 
> compiled and linked in movem. But collision detection library doesn't 
> recoginize the opensg, then error happens
> 
> 2 the opensg's data types are thread-safe, this means all the data type 
> like osg::Node are protected by some mechanism like mutex or something 
> else. when the thread initialized by boost or direct by system accesses 
> these data, error happens.

OpenSG uses very few locks/mutexes etc. internally and none of the 
objects you normally find in a scene are protected in this way. Instead 
in OpenSG every thread is associated with an aspect (essentially a copy 
of the scene), so that threads on different aspects can make changes to 
the scene without interfering with each other. All modified fields that 
are modified are recorded in the threads changelist which the 
application can then apply whenever it is convenient to merge changes 
from one aspect to another.

> If I am right, How can I resolve it?

as I mentioned you are probably accessing OpenSG from a thread the 
system does not know about - probably because you create a boost thread 
instead of an OpenSG thread. The result is that the system does not know 
which OpenSG aspect the thread is supposed to operate on. Anyway, the 
solution is to tell OpenSG about your thread like this:

At the beginning of the thread function:

OSG::UInt32 aspectId = 0;
OSG::ExternalThread::get(0)->initialize(aspectId);

This will make the thread use aspect 0 (which is also the aspect used by 
the thread of the main function of your program).

        Cheers,
                Carsten

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to