Bug 118879 - SerializedScriptValue should be ThreadSafeRefCounted when ENABLE(WORKERS) guard is on
Summary: SerializedScriptValue should be ThreadSafeRefCounted when ENABLE(WORKERS) gua...
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Kwang Yul Seo
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-18 19:14 PDT by Kwang Yul Seo
Modified: 2013-07-19 22:20 PDT (History)
6 users (show)

See Also:


Attachments
Patch (1.51 KB, patch)
2013-07-18 19:18 PDT, Kwang Yul Seo
ap: review-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kwang Yul Seo 2013-07-18 19:14:57 PDT
Because SerializedScriptValue is passed across threads using WorkerMessagingProxy, it should be ThreadSafeRefCounted when ENABLE(WORKERS) guard is on.
Comment 1 Kwang Yul Seo 2013-07-18 19:18:03 PDT
Created attachment 207048 [details]
Patch
Comment 2 Alexey Proskuryakov 2013-07-18 21:41:31 PDT
Comment on attachment 207048 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=207048&action=review

I don't see why this is necessary. But please feel free to mark for review again with additional explanation.

> Source/WebCore/ChangeLog:10
> +        SerializedScriptValue should be ThreadSafeRefCounted when
> +        ENABLE(WORKERS) guard is on because WorkerMessagingProxy passes
> +        SerializedScriptValue across threads.

I don't think that this is a sufficient explanation. An object only needs to be ThreadSafeRefCounted if multiple threads reference/dereference it. But if ownership is cleanly passed from one thread to another, that should not be necessary.
Comment 3 Kwang Yul Seo 2013-07-19 16:31:02 PDT
(In reply to comment #2)
> I don't think that this is a sufficient explanation. An object only needs to be ThreadSafeRefCounted if multiple threads reference/dereference it. But if ownership is cleanly passed from one thread to another, that should not be necessary.

I spent more time digging where these SerializedScriptValue instances are created and where they are actually ref/deref-ed.

And you are right. Currently, all SerializedScriptValue instances that are passed to WorkerMessagingProxy are created in handlePostMessage and the ownership is cleanly passed to a worker thread.

BTW, it seems quite tricky because anyone can break this if he is not careful enough to find the underlying assumption.

I think we need a more systematic way to express the idiom of "create in one thread and pass the ownership to another thread".

Closing this bug as invalid.
Comment 4 Alexey Proskuryakov 2013-07-19 22:20:25 PDT
I think that generally and ideally, out approach should be that no objects are used from multiple threads (and thus nearly nothing is ThreadSafeRefCounted).