Commit 4b9d77c
fix: ensure thread-safe initialization of console line buffers (#4551)
Addresses post-merge feedback from PR #4549 regarding thread-safety
concerns in console buffer lazy initialization.
Replaced nullable StringBuilder fields with Lazy<StringBuilder> to
guarantee thread-safe initialization when multiple threads access
GetConsoleStdOutLineBuffer() or GetConsoleStdErrLineBuffer() concurrently.
The previous implementation using ??= was not thread-safe and could
result in multiple StringBuilder instances being created before
assignment completes, undermining per-context buffer isolation.
Benefits:
- Thread-safe by default with Lazy<T>
- No manual double-checked locking needed
- Cleaner, more idiomatic C# code
- AOT-compatible
Co-authored-by: Claude Sonnet 4.5 <[email protected]>1 parent c01a6fc commit 4b9d77c
1 file changed
+5
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
46 | | - | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | | - | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| |||
0 commit comments