[PR #10653] [MERGED] Fix output stuttering using a ticket lock #28168

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/10653
Author: @lhecker
Created: 7/14/2021
Status: ✅ Merged
Merged: 7/15/2021
Merged by: @undefined

Base: main ← Head: dev/lhecker/ticket-lock


📝 Commits (2)

  • e683f21 Fix output stuttering using a ticket lock
  • b52a9c1 Address reviewer comments

📊 Changes

7 files changed (+111 additions, -22 deletions)

View changed files

📝 src/cascadia/PublicTerminalCore/HwndTerminal.cpp (+6 -11)
📝 src/cascadia/PublicTerminalCore/HwndTerminal.hpp (+1 -1)
📝 src/cascadia/TerminalCore/Terminal.cpp (+4 -4)
📝 src/cascadia/TerminalCore/Terminal.hpp (+13 -4)
📝 src/cascadia/TerminalCore/terminalrenderdata.cpp (+2 -2)
➕ src/inc/til/atomic.h (+29 -0)
➕ src/inc/til/ticket_lock.h (+56 -0)

📄 Description

SRWLOCK, as used by std::shared_mutex, is a inherently unfair mutex
and makes no guarantee whatsoever whether a thread may acquire the lock
in a timely manner. This is problematic for our renderer which relies on
being able to acquire the lock in a timely and predictable manner.
Drawing stalls of up to one minute have been observed in tests.

This issue can be solved with a primitive ticket lock, which is 10x
slower than a SRWLOCK but still sufficiently fast for our use case
(10M locks per second per thread). It's likely that any non-trivial lock
duration will diminish the difference to "negligible".

Validation Steps Performed

  • It still blends ✔️

🔄 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/10653 **Author:** [@lhecker](https://github.com/lhecker) **Created:** 7/14/2021 **Status:** ✅ Merged **Merged:** 7/15/2021 **Merged by:** [@undefined](undefined) **Base:** `main` ← **Head:** `dev/lhecker/ticket-lock` --- ### 📝 Commits (2) - [`e683f21`](https://github.com/microsoft/terminal/commit/e683f21ed73052e5766415831d7f15141b1a4bd8) Fix output stuttering using a ticket lock - [`b52a9c1`](https://github.com/microsoft/terminal/commit/b52a9c1e56feba0a0b3f91a45854aeaa581c247e) Address reviewer comments ### 📊 Changes **7 files changed** (+111 additions, -22 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/PublicTerminalCore/HwndTerminal.cpp` (+6 -11) 📝 `src/cascadia/PublicTerminalCore/HwndTerminal.hpp` (+1 -1) 📝 `src/cascadia/TerminalCore/Terminal.cpp` (+4 -4) 📝 `src/cascadia/TerminalCore/Terminal.hpp` (+13 -4) 📝 `src/cascadia/TerminalCore/terminalrenderdata.cpp` (+2 -2) ➕ `src/inc/til/atomic.h` (+29 -0) ➕ `src/inc/til/ticket_lock.h` (+56 -0) </details> ### 📄 Description `SRWLOCK`, as used by `std::shared_mutex`, is a inherently unfair mutex and makes no guarantee whatsoever whether a thread may acquire the lock in a timely manner. This is problematic for our renderer which relies on being able to acquire the lock in a timely and predictable manner. Drawing stalls of up to one minute have been observed in tests. This issue can be solved with a primitive ticket lock, which is 10x slower than a `SRWLOCK` but still sufficiently fast for our use case (10M locks per second per thread). It's likely that any non-trivial lock duration will diminish the difference to "negligible". ## Validation Steps Performed * It still blends ✔️ --- <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:26:45 +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#28168