Some worker classes can be accessed from both the main thread and worker thread. This would be error-prone. For example, WebEmbeddedWorkerImpl::postTaskToLoader() traversals GC'ed objects on the main thread from the worker thread as follows:
// Called on the worker thread.
void WebEmbeddedWorkerImpl::postTaskToLoader(
const WebTraceLocation& location,
std::unique_ptr<ExecutionContextTask> task) {
// m_mainFrame, frame() and document() are on the main thread.
m_mainFrame->frame()->document()->postTask(location, std::move(task));
}
This may lead to chaos when GC occurs simultaneously. To improve the situation, we might want to separate such classes into 2 parts: one for the main thread, and another for the worker thread. Then, we could limit communication channels among them: ParentFrameTaskRunners for worker->main communication and *something* for main->worker communication. ThreadedMessagingProxyBase and ThreadedObjectProxyBase would be a good example of this way.
This is an incomplete list of classes that can be accessed from both the main thread and worker thread:
- WorkerThread
- WebEmbeddedWorkerImpl
- WebSharedWorkerImpl
Comment 1 by bugdroid1@chromium.org
, Dec 15 2016