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

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon Mar 11 23:33:01 PDT 2019


--- Comment #3 from Fujii Hironori <Hironori.Fujii at sony.com> ---
(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.


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)] {

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/65d0a909/attachment.html>

More information about the webkit-unassigned mailing list