Commit 57f49fd
* Adds concurrency test for OutputBufferImpl race condition
Adds AddStr_And_ClearContents_Concurrent_DoesNotThrow test that
reproduces the race condition in OutputBufferImpl where ClearContents
replaces the Contents reference while AddStr is concurrently iterating.
See #5130.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Adds concurrency tests, benchmark, and plan for #5130
- Expanded OutputBufferImplConcurrencyTests with 4 tests covering:
AddStr+ClearContents, FillRect+ClearContents, Move+AddStr+ClearContents,
and a three-way concurrent test
- Added OutputBufferBenchmark for perf baseline (AddStr, FillRect,
ClearContents, SetSize, TypicalDrawCycle)
- Added implementation plan in plans/
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Refactor OutputBufferImpl for thread safety
Replaced locking on Contents with a dedicated _contentsLock object to ensure safe concurrent access to buffer state (Contents, DirtyLines, Clip, etc.). Refactored buffer management methods (ClearContents, SetSize, FillRect, Move, IsValidLocation) to use the new lock. Updated FillRect and AddGrapheme to avoid race conditions. Improved documentation and comments for concurrency. Moved SetCellUrl/GetCellUrl implementations under the lock. In OutputBufferImplConcurrencyTests, reordered and moved helper methods for clarity; no test logic changes. No public API changes, but internal concurrency is now robust.
* Refactor StringExtensions for style and consistency
Refactored methods to use expression-bodied members and improved code style (constants, variable declarations, and formatting). Added and then removed `IsSurrogatePair` and `MakePrintable` extension methods, resulting in no net functional changes. All updates are stylistic and organizational.
* Fix race condition in FillRect(Rectangle, char) overload
The char overload called Move() + AddRune() without holding _contentsLock,
allowing concurrent threads to corrupt Col/Row between the two calls and
write characters to wrong positions.
Fix: delegate to FillRect(Rectangle, Rune) which holds the lock atomically.
Added test proving the race (detected wrong-position writes in <13ms before fix).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Added null check in OutputBufferImpl.cs WriteGrapheme. Introduced locking in RuneExtensions.cs for thread-safe Unicode width calculation.
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: BDisp <bd.bdisp@gmail.com>
1 parent 688c292 commit 57f49fd
8 files changed
Lines changed: 993 additions & 413 deletions
File tree
- Examples/UICatalog/Scenarios
- Terminal.Gui
- App
- Mouse
- Drivers/Output
- Text
- Tests
- Benchmarks/ConsoleDrivers/OutputBuffer
- UnitTestsParallelizable/Drivers/Output
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | | - | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
| 166 | + | |
| 167 | + | |
166 | 168 | | |
167 | 169 | | |
168 | 170 | | |
| |||
259 | 261 | | |
260 | 262 | | |
261 | 263 | | |
262 | | - | |
| 264 | + | |
263 | 265 | | |
264 | 266 | | |
265 | 267 | | |
| |||
322 | 324 | | |
323 | 325 | | |
324 | 326 | | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
325 | 404 | | |
326 | 405 | | |
327 | 406 | | |
| |||
643 | 722 | | |
644 | 723 | | |
645 | 724 | | |
646 | | - | |
647 | | - | |
648 | | - | |
649 | | - | |
650 | | - | |
651 | | - | |
652 | | - | |
653 | | - | |
654 | | - | |
655 | | - | |
656 | | - | |
657 | | - | |
658 | | - | |
659 | | - | |
660 | | - | |
661 | | - | |
662 | | - | |
663 | | - | |
664 | | - | |
665 | | - | |
666 | | - | |
667 | | - | |
668 | | - | |
669 | | - | |
670 | | - | |
671 | | - | |
672 | | - | |
673 | | - | |
674 | | - | |
675 | | - | |
676 | | - | |
677 | | - | |
678 | | - | |
679 | | - | |
680 | | - | |
681 | | - | |
682 | | - | |
683 | | - | |
684 | | - | |
685 | | - | |
686 | | - | |
687 | | - | |
688 | | - | |
689 | | - | |
690 | | - | |
691 | | - | |
692 | | - | |
693 | | - | |
694 | | - | |
695 | | - | |
696 | | - | |
697 | | - | |
698 | | - | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
703 | | - | |
704 | | - | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
713 | | - | |
714 | | - | |
715 | | - | |
716 | | - | |
717 | | - | |
718 | | - | |
719 | | - | |
720 | | - | |
721 | | - | |
722 | | - | |
723 | | - | |
724 | | - | |
725 | 725 | | |
726 | 726 | | |
727 | 727 | | |
| |||
884 | 884 | | |
885 | 885 | | |
886 | 886 | | |
887 | | - | |
888 | | - | |
889 | | - | |
890 | | - | |
891 | | - | |
892 | | - | |
893 | | - | |
894 | | - | |
895 | | - | |
896 | | - | |
897 | | - | |
898 | | - | |
899 | | - | |
900 | | - | |
901 | | - | |
902 | | - | |
903 | | - | |
904 | | - | |
905 | | - | |
906 | | - | |
907 | | - | |
908 | | - | |
909 | | - | |
910 | | - | |
911 | | - | |
912 | | - | |
913 | | - | |
914 | | - | |
915 | | - | |
916 | | - | |
917 | 887 | | |
918 | 888 | | |
919 | 889 | | |
| |||
960 | 930 | | |
961 | 931 | | |
962 | 932 | | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
963 | 959 | | |
964 | 960 | | |
965 | 961 | | |
| |||
1000 | 996 | | |
1001 | 997 | | |
1002 | 998 | | |
| 999 | + | |
| 1000 | + | |
1003 | 1001 | | |
1004 | 1002 | | |
1005 | 1003 | | |
| |||
1084 | 1082 | | |
1085 | 1083 | | |
1086 | 1084 | | |
1087 | | - | |
1088 | | - | |
| 1085 | + | |
| 1086 | + | |
1089 | 1087 | | |
1090 | 1088 | | |
1091 | 1089 | | |
| |||
1117 | 1115 | | |
1118 | 1116 | | |
1119 | 1117 | | |
1120 | | - | |
| 1118 | + | |
1121 | 1119 | | |
1122 | 1120 | | |
1123 | 1121 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
5 | | - | |
6 | | - | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
| |||
102 | 101 | | |
103 | 102 | | |
104 | 103 | | |
105 | | - | |
| 104 | + | |
106 | 105 | | |
107 | 106 | | |
108 | 107 | | |
| |||
284 | 283 | | |
285 | 284 | | |
286 | 285 | | |
287 | | - | |
| 286 | + | |
288 | 287 | | |
289 | 288 | | |
290 | 289 | | |
| |||
0 commit comments