Repository navigation
Conversation
Motivation: A thread executing a DispatchExecutor queue must run its reentrant tasks inline (e.g. component.add(dependency) from init()). The end of run() released the queue before clearing the executing thread: m_scheduled.set(false); m_executingThread = null; Scenario: thread A, from the threadpool, finishes the queue and releases it. Thread B (a REMOVED event or stop(), which bypass the threadpool) then takes the queue over and sets itself as the executing thread. A then overwrites it with null. When a task running in B calls execute() again, B is no longer recognized as the queue owner: the task is queued instead of being run inline, and the component goes on (e.g. start()) before it has run. Modification: Rewrite DispatchExecutor around a counter of pending tasks: the thread which increments it from 0 owns the queue and runs tasks until it drops back to 0. The owner only clears the executing thread if no other thread has taken the queue over in the meantime. Task execution never throws, so the counter stays consistent. Unused methods are removed. Result: Reentrant tasks are always executed inline by the thread which owns the queue, and DispatchExecutor is much simpler.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation:
A thread executing a DispatchExecutor queue must run its reentrant tasks inline (e.g. component.add(dependency) from init()). The end of run() released the queue before clearing the executing thread:
m_scheduled.set(false);
m_executingThread = null;
Scenario: thread A, from the threadpool, finishes the queue and releases it. Thread B (a REMOVED event or stop(), which bypass the threadpool) then takes the queue over and sets itself as the executing thread. A then overwrites it with null. When a task running in B calls execute() again, B is no longer recognized as the queue owner: the task is queued instead of being run inline, and the component goes on (e.g. start()) before it has run.
Modification:
Rewrite DispatchExecutor around a counter of pending tasks: the thread which increments it from 0 owns the queue and runs tasks until it drops back to 0. The owner only clears the executing thread if no other thread has taken the queue over in the meantime. Task execution never throws, so the counter stays consistent. Unused methods are removed.
Result:
Reentrant tasks are always executed inline by the thread which owns the queue, and DispatchExecutor is much simpler.