Ah ok, Carsten thanks again,

Cheers,

Georg

-----Ursprüngliche Nachricht-----
Von: Carsten Neumann [mailto:carsten_neum...@gmx.net] 
Gesendet: Freitag, 4. Dezember 2009 22:57
An: georg.wuen...@machineering.de
Cc: opensg-users@lists.sourceforge.net
Betreff: Re: AW: Threading/Aspects [WAS: OSG::Foreground resizing problem]

        Hello Georg,

Georg Wünsch wrote:
> I am having a model that keeps a root node of a scene. It also manipulates
> that scene storing a lot of references to parts of the scene in the models
> NodePtrs. It does so by the background thread simulating some movements
and
> changes to the scene, while the user is clicking controls in the views in
> the gui thread. 
> 
> The controls are connected to the model and issue some properties to
change
> for example colors positions etc. so these are changed using gui controls.
> At the same moment, I seem to be using the same nodeptrs to manipulate by
> the gui thread by the simulation thread, also changing positions etc.
> 
> I think this leads to the crash as every nodeptr variable is actually used
> in two aspects, right?

in 1.x the Ptr types check the aspect associated with the current thread 
and act on the container copy for the current aspect, so that is fine.

> How would I have to set it up to have my model keep track of the nodeptrs
> and manipulate them from both gui and simulation threads?
> 
> Do I need to implement the model using FieldContaines and the same itself
to
> avoid this problem? If I'd protect the models parts by mutices or the
like,
> the gui thread and the simulation thread would be serialized in their
access
> to the model, which only occurs when user interaction takes place. Still
the
> rendering might be unaffected as this is a timer based thing done by the
gui
> thread.

yeah, but the idea (and we believe strength) of OpenSG is that you 
should not need to have a mutex for a case like this ;)

> So far so good. There is one question left: My model keeps a NodePtr
called
> root. This root is being used by the window to go into a viewport for
> rendering. But as mentioned above this root is also the base for changing
> the scene during simulation. How would I make a copy of the NodePtr root
and
> make it stick to another aspect?

see above. Pointer to containers are usable across aspects (in 1.x, for 
2.0 you need to use MTRefPtr to get this behaviour).

> Class model
> {
>       NodePtr root;
> Public:
> ...
>       NodePtr getScene() { return root; };
> }
> 
> Simulation thread: mutex protected access within aspect A0
> 
>       model->Mutex.lock();
> 
>       beginEditCP(..);
>       TransformPtr
>
trafo(TransformPtr::dcast(model->getScene()->getChild(29)->getCore())->setMa
> trix(...);
>       endEditCP(..);
> 
>       model->Mutex.unlock();
> 
> 
> Gui Thread:
> 
>       Mouse move: --> Mutex protected access within Aspect A0
>                        --> mouse interaction will slow down simulation,
> but don’t care at this moment
>       model->Mutex.lock();
>       
>       mgr->hit(x,y);
> 
>       beginEditCP(..);
>       TransformPtr
>
trafo(TransformPtr::dcast(model->getScene()->getChild(29)->getCore())->setMa
> trix(...);
>       endEditCP(..);
>       
>       model->Mutex.unlock();
> 
> 
> GUI-Thread-Rendering:
>       Rendering should run in parallel, therefore in aspect A1?!, 
>         but how tell the window that now there is another aspect??

why should it care? It just renders the scene in aspect A0. Whenever it 
is convenient you apply changes from the simulation in aspect A1 to 
aspect A0 and the next time an image is rendered it will show the 
updated results.
Think about using aspects as using two totally independent scenes: one 
that you display and one that you currently modify.

        Cheers,
                Carsten




------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing. 
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to