How would this impact performance? Would it improve it do you think?<div>W<br><div><br><br><div class="gmail_quote">On Mon, Oct 11, 2010 at 10:35 PM, David Gobbi <span dir="ltr"><<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hi All,<br>
<br>
The VTK weak pointer implementation is not thread safe because it can<br>
be used just like a regular pointer, even though the object itself<br>
might be deleted by a separate thread at any time.<br>
<br>
By comparison, "safe" weak pointer like in boost and Qt cannot be used<br>
in place of ordinary pointers.  Instead, in order to use them their<br>
"GetPointer()"-like methods increment the reference count and then<br>
return a smart pointer, which is guaranteed to be valid until it goes<br>
out of scope:<br>
<br>
vtkSmartPointer<SomeClass> smartPtr = weakPtr.GetPointer();<br>
if (smartPtr.GetPointer() != 0)<br>
  {<br>
  // do something with smartPtr<br>
  }<br>
// reference count decremented when smartPtr goes out of scope<br>
<br>
Because VTK's vtkWeakPointer::GetPointer() does not return a smart<br>
pointer or do any thread locking, thread-safe use of vtkWeakPointer<br>
requires the following:<br>
<br>
vtkSimpleCriticalSection critSec;<br>
critSec.Lock();<br>
vtkSmartPointer<SomeClass> smartPtr = weakPtr.GetPointer();<br>
critSec.Unlock();<br>
if (smartPtr.GetPointer() != 0)<br>
  {<br>
  // do something with smartPtr<br>
  }<br>
<br>
If weakPtr.GetPointer() was changed to return a smart pointer, then it<br>
could do the locking internally.  This change would be mostly, but not<br>
completely, backwards compatible.  What do people think?<br>
<br>
  David<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtk-developers" target="_blank">http://www.vtk.org/mailman/listinfo/vtk-developers</a><br>
<br>
</blockquote></div><br><br clear="all"><br>-- <br>William J. Schroeder, PhD<br>Kitware, Inc.<br>28 Corporate Drive<br>Clifton Park, NY 12065<br><a href="mailto:will.schroeder@kitware.com">will.schroeder@kitware.com</a><br>

<a href="http://www.kitware.com">http://www.kitware.com</a><br>(518) 881-4902<br>
</div></div>