The following revision refers to this bug:
https://chromium.googlesource.com/chromium/src.git/+/cfa01627d191d2a1a801943994f287b8cf5b1c42
commit cfa01627d191d2a1a801943994f287b8cf5b1c42
Author: nhiroki <nhiroki@chromium.org>
Date: Fri Sep 23 11:29:28 2016
Worker: Unify worker thread shutdown sequences.
This CL unifies worker thread shutdown sequences to fix a crash and simplify
shutdown.
<Problem>
When termination is requested on the main thread before WorkerThread is
initialized on the worker thread, shutdown sequence runs in a different way from
regular shutdown sequence: initialization sequence seamlessly switches to
shutdown sequence and asks the main thread to destroy WorkerThread
(see WorkerThread::initializeOnWorkerThread).
This causes a crash in a following scenario:
1) Request to start the worker thread from the main thread.
2) Post a task to the worker thread from the main thread.
3) Request to terminate the worker thread from the main thread.
4) Start initialziation sequence and switch to shutdown sequence on the worker
thread.
5) WorkerThread is destroyed on the main thread.
6) The posted task runs on the worker thread and crashes.
<Solution>
This CL makes the initialization sequence complete regardless of termination
request and defer to the regular shutdown task posted from the main thread.
Other tasks also posted from the main thread(*) are guaranteed to be drained
until the shutdown task runs.
<Appendix>
Regarding (*), you might wonder if tasks posted from/to the worker thread cannot
be guaranteed to be drained until the shutdown tasks run. This case is covered
by other mechanism. Let's consider it in following 2 cases:
1) An uninitialized worker thread does not post a task to itself, so there
should be no tasks when termination happens before initialization.
2) Otherwise, WorkerBackingThread::shutdown drains all tasks.
Therefore, we can ensure that tasks posted from the worker thread also never run
after shutdown.
BUG=632810, 640843
Review-Url: https://codereview.chromium.org/2280523002
Cr-Commit-Position: refs/heads/master@{#420592}
[modify] https://crrev.com/cfa01627d191d2a1a801943994f287b8cf5b1c42/third_party/WebKit/Source/core/workers/WorkerThread.cpp
[modify] https://crrev.com/cfa01627d191d2a1a801943994f287b8cf5b1c42/third_party/WebKit/Source/core/workers/WorkerThread.h
[modify] https://crrev.com/cfa01627d191d2a1a801943994f287b8cf5b1c42/third_party/WebKit/Source/core/workers/WorkerThreadTest.cpp
Comment 1 by nhiroki@chromium.org
, Aug 25 2016