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

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Mar 12 10:11:03 PDT 2019


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

--- Comment #6 from Chris Dumez <cdumez at apple.com> ---
(In reply to Geoffrey Garen from comment #5)
> Honestly, it's probably a bug that WeakReference is ThreadSafeRefCounted.
> (It should just be RefCounted.) None of the data in WeakPtr, WeakReference,
> or WeakPtrFactory is thread-safe.
> 
> I left WeakReference ThreadSafeRefCounted out of an abundance of caution,
> because it was originally written that way and I didn't know if there any
> clients needed the atomic reference count.
> 
> If we wanted a thread-safe approach to weak references, we could create one,
> and it would be a distinct class with a distinct implementation. (All
> operations would need to be atomic, get() and operator->() would need to
> return RefPtr, and operator*() would need to return Ref.)

I have leveraged the fact that it is ThreadSafeRefcounted in my code for cases where I jump to a background thread and then back to the main thread. I only create the WeakPtr and use it on the main thread, which is where my object live, so this is safe. It is only safe though because it is ThreadSafeRefCounted.

That said, I agree with the closing on this bug and I do not think we should try and promote usage of WeakPtr from different threads.

Just because an object is ThreadSafeRefCounted does not imply its methods are thread safe and that you use it from different threads.

-- 
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/e78fb751/attachment-0001.html>


More information about the webkit-unassigned mailing list