[Webkit-unassigned] [Bug 195605] makeWeakPtr isn't thread-safe

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Mar 12 07:01:01 PDT 2019


https://bugs.webkit.org/show_bug.cgi?id=195605

--- Comment #4 from Chris Dumez <cdumez at apple.com> ---
(In reply to Fujii Hironori from comment #3)
> (In reply to Chris Dumez from comment #2)
> > Is this a problem with actual code right now? Can you provide an example?
> > WeakPtr is normally not used across thread since you could check on one line
> > that the weak pointer is not null and then dereference it on the next line,
> > by which time your object may be dead already.
> 
> WTF::WeakReference is a sub-class of ThreadSafeRefCounted. 
> 
> > class WeakReference : public ThreadSafeRefCounted<WeakReference<T>> {
> 
> And, WTF::WeakPtr doesn't have a method like weak_ptr::lock.
> 
>   std::weak_ptr::lock
>   https://en.cppreference.com/w/cpp/memory/weak_ptr/lock
> 
> These two facts mean WTF::WeakPtr should be used in a single thread, but its
> WTF::WeakReference can be held in multiple threads by design.
> 
> And, it's easy to find code looks like the following under WebCore/platform.
> 
> > callOnMainThread([weakPtr = makeWeakPtr(*this)] {

So no concrete example where there is an actual problem? CallonMainThread() is frequently used on the main thread to call something asynchronously and does not imply multithreading. Also, it is ok to temporarily pass a weakptr to another thread (since ThreadSafeRefcounted) as long as it is created and used on the thread where the object lives (which may or may not be the main thread).

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20190312/2afa74e6/attachment.html>


More information about the webkit-unassigned mailing list