Hi,

I try to catch up on things past an other busy week.

On Thursday, March 29, 2012 00:22:46 ThorstenB wrote:
> Mathias, maybe you can have a look at the simgear changes. Maybe you see
> a way to improve this even further - i.e. do we still need all these
> cache maps? Or could we simply rely on some OSG cache in some places?

Just looking quick over what you checked in, I think that this needs some 
improovements:

The change just returns pointers to objects you get from the observer_ptr.
In general, this is not exactly thread safe. I do not see currently if you can 
ensure from a higher level that this is not a problem or not.

In general consider the following situation:

Thread 1 has an observer_ptr to A.

Thread 2 owns the last reference to A.

Thread 1 gets the still valid raw pointer to A from the observer_ptr.

Thread 2 releases the last reference to A and deletes it.

Thread 1 assigns the raw pointer to a ref_ptr. This probably ends in a 
segfault.


If you work with weak pointers/observer_ptr you need to use the lock method. 
That one gives you a atomically a dead or alive ref_ptr to A. If you have this 
ref_ptr in our hands, you own a thread safe reference which makes sure that 
nobody deletes the object. If your ref_ptr is invalid. An other one was faster 
on unreferencing.
In effect this groups step 3 and 5 into an atomic operation which can not be 
intercepted by step 4 in the example above.

So, if you use this kind of weak stuff, you need to ensure that all the call 
chain from getting the ref_ptr from any cache down to adding this object to 
the scenegraph does not use raw pointers. Also the initial ref_ptr in this 
chain must be gained by observer_ptr::lock().

Regarding the effects, I don't think we can rely on any caching in osg since we 
do not currently use any osg based loader mechanism to gain these objects.
At least nothing that I know of.

Greetings

Mathias

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to