[PR #11189] [MERGED] Attempt to make the monarch more thread safe. #28444

Open
opened 2026-01-31 09:28:33 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/11189
Author: @Rosefield
Created: 9/9/2021
Status: ✅ Merged
Merged: 9/21/2021
Merged by: @undefined

Base: main ← Head: bug/make-monarch-more-thread-safe


📝 Commits (10+)

  • 4eedfcc Attempt to make the monarch more thread safe.
  • 825dfc3 spelling and formatting.
  • 91f1845 Use _forEachPeasant correctly, and make the dead peasant use the error code we expect a dead peasant to have.
  • e386d6f Some code review
  • f765728 Actually compiling the code is a good idea.
  • 5f632f4 Change a fail_fast to an assert
  • ee463aa More code review changes: be less trict about memory ordering
  • 3aeaeed Merge remote-tracking branch 'origin/main' into bug/make-monarch-more-thread-safe
  • 2f0db9e Refactor _getMostRecentPeasantID so that we dont need to have a recursive_mutex. This is done by making _getPeasant not remove from _mruPeasants on failure, and _getMostRecentPeasantID handle its own cleanup.
  • e1c2f53 make the spellchecker happy

📊 Changes

4 files changed (+261 additions, -154 deletions)

View changed files

📝 src/cascadia/Remoting/Monarch.cpp (+183 -105)
📝 src/cascadia/Remoting/Monarch.h (+50 -30)
📝 src/cascadia/Remoting/WindowManager.cpp (+8 -0)
📝 src/cascadia/UnitTests_Remoting/RemotingTests.cpp (+20 -19)

📄 Description

Summary of the Pull Request

References

#11083
#11143

PR Checklist

  • Closes #xxx
  • CLA signed. If not, go over here and sign the CLA
  • Tests added/passed
  • Documentation updated. If checked, please file a pull request on our docs repo and link it here: #xxx
  • Schema updated.
  • I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

Detailed Description of the Pull Request / Additional comments

While testing the save/quit features a number of issues were found that were caused by poor synchronization on the monarch, resulting in various unexpected crashes. Because this uses std collections, and I didn't see any builtin winrt multithreaded containers I went with the somewhat heavy-handed mutex approach.

e.g.

This also makes it so that on quit peasants don't try to become the monarch, and the monarch closes their peasant last to prevent elections from happening.

Validation Steps Performed

Create many windows (hold down ctrl-shift-n) then use the quit action from peasants/the monarch to make sure everything closes properly.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/11189 **Author:** [@Rosefield](https://github.com/Rosefield) **Created:** 9/9/2021 **Status:** ✅ Merged **Merged:** 9/21/2021 **Merged by:** [@undefined](undefined) **Base:** `main` ← **Head:** `bug/make-monarch-more-thread-safe` --- ### 📝 Commits (10+) - [`4eedfcc`](https://github.com/microsoft/terminal/commit/4eedfcc709283e604786a3d2569f7eb185600419) Attempt to make the monarch more thread safe. - [`825dfc3`](https://github.com/microsoft/terminal/commit/825dfc3613c9d1a9d0d40229d6a487bcc7eecf22) spelling and formatting. - [`91f1845`](https://github.com/microsoft/terminal/commit/91f18453bf1e9abc2d1e98b3f2b5ea15d1985bbc) Use _forEachPeasant correctly, and make the dead peasant use the error code we expect a dead peasant to have. - [`e386d6f`](https://github.com/microsoft/terminal/commit/e386d6f6c731092d282806ef0f65be4903973eb3) Some code review - [`f765728`](https://github.com/microsoft/terminal/commit/f765728e88d80eba68c0d56c424400757efe092a) Actually compiling the code is a good idea. - [`5f632f4`](https://github.com/microsoft/terminal/commit/5f632f4602fccd29d3fdf04459a2675f8044224a) Change a fail_fast to an assert - [`ee463aa`](https://github.com/microsoft/terminal/commit/ee463aa6b31032aeede694e50ae9d4576de54c67) More code review changes: be less trict about memory ordering - [`3aeaeed`](https://github.com/microsoft/terminal/commit/3aeaeedb569706cae45431ef8f31be768827fc78) Merge remote-tracking branch 'origin/main' into bug/make-monarch-more-thread-safe - [`2f0db9e`](https://github.com/microsoft/terminal/commit/2f0db9e23c94e0fe6fbdbb963804bc5aa63af671) Refactor _getMostRecentPeasantID so that we dont need to have a recursive_mutex. This is done by making _getPeasant not remove from _mruPeasants on failure, and _getMostRecentPeasantID handle its own cleanup. - [`e1c2f53`](https://github.com/microsoft/terminal/commit/e1c2f5380f658cfb32213bb7529164ae2fc324c5) make the spellchecker happy ### 📊 Changes **4 files changed** (+261 additions, -154 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/Remoting/Monarch.cpp` (+183 -105) 📝 `src/cascadia/Remoting/Monarch.h` (+50 -30) 📝 `src/cascadia/Remoting/WindowManager.cpp` (+8 -0) 📝 `src/cascadia/UnitTests_Remoting/RemotingTests.cpp` (+20 -19) </details> ### 📄 Description <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request <!-- Other than the issue solved, is this relevant to any other issues/existing PRs? --> ## References #11083 #11143 <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [ ] Closes #xxx * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [x] Tests added/passed * [ ] Documentation updated. If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx * [ ] Schema updated. * [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments While testing the save/quit features a number of issues were found that were caused by poor synchronization on the monarch, resulting in various unexpected crashes. Because this uses std collections, and I didn't see any builtin winrt multithreaded containers I went with the somewhat heavy-handed mutex approach. e.g. - https://github.com/microsoft/terminal/pull/11083#issuecomment-916218353 - https://github.com/microsoft/terminal/pull/11083#issuecomment-916220521 - https://github.com/microsoft/terminal/pull/11143/#discussion_r704738433 This also makes it so that on quit peasants don't try to become the monarch, and the monarch closes their peasant last to prevent elections from happening. <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed Create many windows (hold down ctrl-shift-n) then use the quit action from peasants/the monarch to make sure everything closes properly. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:28:33 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#28444