[osg-submissions] Use atomic reference counts
Mathias Fröhlich
M.Froehlich at science-computing.de
Thu Jun 19 22:59:37 PDT 2008
Robert,
On Thursday 19 June 2008 17:40, Robert Osfield wrote:
> I've have just done a trial integration of OpenThreads::Atomic into
> osg::Referenced using your changes, and performance results are pretty
> encouraging under Linux/Intel quad core - I've seen 2.8 to 3.8%
> improvement in overall framerate on a large town model I have, this
> for the whole frame so means that the actual improvement during
> cull/draw is better than this percentage.
:)
Yep, that atomic stuff is just worth it ...
> I won't commit the changes I've just merged though, as I recall from
> my first pass review that the solution for the observers wasn't ideal,
> so I'll go back and review these details and look for a better
> solution right now.
Well, we can discuss about that. Such a single lock per observer will be save
also.
But what is there should be thread safe. That is the typical RCU approach we
can see in lockless algorithms. This is also what will just happen in some
sense in most mutex implementations.
The key is that the pointer value needs to be changed atomically. If we do not
have the observer pointer there we allocate a new observer data structure and
try to write that to the referenced. If an other thread did the same at the
same time, we will fail on that atomic compare and swap operation on that
pointer. In this case we just delete the yet unused observer pointer and use
the other one that is now there. If our thread is successful to write that
pointer we use our new data for the observers.
The observer insert/remove is then guarded by the mutex in the observer data
stuff. So this is safe too.
The 'single observer lock' approach will serialize the observer modification
globaly. While I believe that this is not a big problem in *almost* all
cases. I think that we should prefere a completely paralell implementation if
this one is that easy to have.
Greetings and thanks
Mathias
--
Dr. Mathias Fröhlich, science + computing ag, Software Solutions
Hagellocher Weg 71-75, D-72070 Tuebingen, Germany
Phone: +49 7071 9457-268, Fax: +49 7071 9457-511
--
Vorstand/Board of Management:
Dr. Bernd Finkbeiner, Dr. Florian Geyer,
Dr. Roland Niemeier, Dr. Arno Steitz, Dr. Ingrid Zech
Vorsitzender des Aufsichtsrats/
Chairman of the Supervisory Board:
Prof. Dr. Hanns Ruder
Sitz/Registered Office: Tuebingen
Registergericht/Registration Court: Stuttgart
Registernummer/Commercial Register No.: HRB 382196
More information about the osg-submissions
mailing list