Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Prioritize thread pause()/resume() calls - #10174

Closed
kkaefer wants to merge 2 commits into
masterfrom
prioritize-thread-pause-resume
Closed

kkaefer wants to merge 2 commits into
masterfrom
prioritize-thread-pause-resume

Conversation

@kkaefer

@kkaefer kkaefer commented Oct 10, 2017 •

Copy link
Copy Markdown
Member

Previously we had the capability to pause on the Thread object, which used regular tasks to pause the RunLoop by blocking it. Instead, we can now pause the entire RunLoop and prevent it from processing items. This means that a pause() call is no longer treated as a regular task. Instead, it will take precedence over scheduled tasks, which means that a pause() call takes effect much more instantly since the RunLoop doesn't process the queue before the pause() task. Having pause() take effect much quicker is useful for situations where stopping the loop quickly is important, e.g. when the application goes to the background on iOS, and we have to stop processing tasks that access the file system. It also reduces the length of the blocking pause() call since the time until the RunLoop is paused is shortened.

RunLoop already has a queue, and has the ability to schedule weak mailboxes, so we can remove the duplicate code.
@kkaefer kkaefer changed the title Prioritize thread pause resume Prioritize thread pause()/resume() calls Oct 10, 2017
@kkaefer

kkaefer commented Oct 10, 2017

Copy link
Copy Markdown
Member Author

Improves the timeout between the pause() call and actually pausing write operations, as per #10174.

@kkaefer
kkaefer force-pushed the prioritize-thread-pause-resume branch from 5ab0102 to e16c97c Compare October 10, 2017 17:19
Previously we had the capability to pause on the Thread object, which used regular tasks to pause the RunLoop by blocking it. Instead, we can now pause the entire RunLoop and prevent it from processing items. This means that a pause() call is no longer treated as a regular task. Instead, it will take precedence over scheduled tasks, which means that a pause() call takes effect much more instantly since the RunLoop doesn't process the queue before the pause() task. Having pause() take effect much quicker is useful for situations where stopping the loop quickly is important, e.g. when the application goes to the background on iOS, and we have to stop processing tasks that access the file system. It also reduces the length of the blocking pause() call since the time until the RunLoop is paused is shortened.
@kkaefer
kkaefer force-pushed the prioritize-thread-pause-resume branch from e16c97c to 329282f Compare October 10, 2017 17:34

@jfirebaugh jfirebaugh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to support pause/resume from arbitrary threads? I shudder at trying to reason about pauses and resumes from multiple threads racing against each other. Allowing only the creating thread to pause/resume the created thread is much easier to understand. Could we preserve this restriction?

The previous implementation guaranteed that no activity could happen on the RunLoop (because it would be blocked inside process). This implementation guarantees that process won't do any work, but it doesn't guarantee that there is no other work happening on the underlying event loop. For example, I believe that events related to the addWatch/removeWatch methods in the default implementation will still be dispatched on a "paused" RunLoop. Is that the desired behavior?

Comment thread test/util/thread.test.cpp
loop.run();
}

TEST(Thread, TestImmediatePause) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a timing-dependent test, which almost inevitably seem to fail intermittently.

lock.unlock();

Mailbox::maybeReceive(mailbox);
loop->schedule(mailbox);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@kkaefer kkaefer added the Core The cross-platform C++ core, aka mbgl label Oct 11, 2017
@kkaefer

kkaefer commented Jan 24, 2018

Copy link
Copy Markdown
Member Author

Closing in favor of #11005

@kkaefer kkaefer closed this Jan 24, 2018
@kkaefer
kkaefer deleted the prioritize-thread-pause-resume branch January 24, 2018 01:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Core The cross-platform C++ core, aka mbgl

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants