[vtk-developers] Weak pointers and thread safety

Stephane PLOIX stephane.ploix at edf.fr
Tue Oct 12 09:21:54 EDT 2010


Hi,

I think we should be carefull about the multithreading improvements. 
They are certainly necessary, but some carefull tests are needed to see if 
multithreading should be supported implicitely, with potential performance 
issues, or explicitely, with some overhead for developers.

I am more in favor of being explicit, at least now that we are only trying 
to find the best programming model. 
Maybe a class vtkThreadedWeakPointer with critical section?

Stephane

  
 
Stephane PLOIX
Pilote Opérationnel - Visualisation scientifique
EDF - R&D
SINETICS
1, Av du Général de Gaulle
92140 Clamart
 
stephane.ploix at edf.fr
Tél. : +33 (0) 1 47 65 51 10
  
Un geste simple pour l'environnement, n'imprimez ce message que si vous en 
avez l'utilité.




will.schroeder at kitware.com 
Envoyé par : vtk-developers-bounces at vtk.org
12/10/2010 12:32

A
david.gobbi at gmail.com
cc
vtk-developers at vtk.org
Objet
Re: [vtk-developers] Weak pointers and thread safety






How would this impact performance? Would it improve it do you think?
W


On Mon, Oct 11, 2010 at 10:35 PM, David Gobbi <david.gobbi at gmail.com> 
wrote:
Hi All,

The VTK weak pointer implementation is not thread safe because it can
be used just like a regular pointer, even though the object itself
might be deleted by a separate thread at any time.

By comparison, "safe" weak pointer like in boost and Qt cannot be used
in place of ordinary pointers.  Instead, in order to use them their
"GetPointer()"-like methods increment the reference count and then
return a smart pointer, which is guaranteed to be valid until it goes
out of scope:

vtkSmartPointer<SomeClass> smartPtr = weakPtr.GetPointer();
if (smartPtr.GetPointer() != 0)
 {
 // do something with smartPtr
 }
// reference count decremented when smartPtr goes out of scope

Because VTK's vtkWeakPointer::GetPointer() does not return a smart
pointer or do any thread locking, thread-safe use of vtkWeakPointer
requires the following:

vtkSimpleCriticalSection critSec;
critSec.Lock();
vtkSmartPointer<SomeClass> smartPtr = weakPtr.GetPointer();
critSec.Unlock();
if (smartPtr.GetPointer() != 0)
 {
 // do something with smartPtr
 }

If weakPtr.GetPointer() was changed to return a smart pointer, then it
could do the locking internally.  This change would be mostly, but not
completely, backwards compatible.  What do people think?

 David
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtk-developers




-- 
William J. Schroeder, PhD
Kitware, Inc.
28 Corporate Drive
Clifton Park, NY 12065
will.schroeder at kitware.com
http://www.kitware.com
(518) 881-4902_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtk-developers





Ce message et toutes les pièces jointes (ci-après le 'Message') sont établis à l'intention exclusive des destinataires et les informations qui y figurent sont strictement confidentielles. Toute utilisation de ce Message non conforme à sa destination, toute diffusion ou toute publication totale ou partielle, est interdite sauf autorisation expresse.

Si vous n'êtes pas le destinataire de ce Message, il vous est interdit de le copier, de le faire suivre, de le divulguer ou d'en utiliser tout ou partie. Si vous avez reçu ce Message par erreur, merci de le supprimer de votre système, ainsi que toutes ses copies, et de n'en garder aucune trace sur quelque support que ce soit. Nous vous remercions également d'en avertir immédiatement l'expéditeur par retour du message.

Il est impossible de garantir que les communications par messagerie électronique arrivent en temps utile, sont sécurisées ou dénuées de toute erreur ou virus.
____________________________________________________

This message and any attachments (the 'Message') are intended solely for the addressees. The information contained in this Message is confidential. Any use of information contained in this Message not in accord with its purpose, any dissemination or disclosure, either whole or partial, is prohibited except formal approval.

If you are not the addressee, you may not copy, forward, disclose or use any part of it. If you have received this message in error, please delete it and all copies from your system and notify the sender immediately by return message.

E-mail communication cannot be guaranteed to be timely secure, error or virus-free.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20101012/439c161a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 1816 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20101012/439c161a/attachment-0002.gif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 1151 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20101012/439c161a/attachment-0003.gif>


More information about the vtk-developers mailing list