startup_stubs/inflate: fix fixed_block static-init data race #1481

Merged
tedin7 merged 1 commit from upstream-pr/1488 into main 2026-11-24 13:28:42 +00:00
tedin7 commented 2026-11-24 12:49:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T12:49:59Z.


Summary

  • Fix a multithreaded static-initialization data race in x2w_inflate::fixed_block (src/startup_stubs/inflate.h). Previously, fixed_block guarded non-atomic static Huffman lencode, distcode initialization with a non-atomic static bool ready = false, allowing concurrent callers to observe ready == true before table construction finished or race on initialization.
  • Replace the racy flag with C++11/17 thread-safe function-local static const FixedTables tables = make_fixed_tables(); initialization ([stmt.dcl]/4), keeping the hot path lock-free and immutable after construction.
  • Extend tests/startup_inflate_status.cpp with a multi-threaded fixed_lit_stream stress test (check_fixed_multithreaded) that synchronizes 8 std::threads at a start barrier before invoking inflate_zlib_ex concurrently, verifying InflateStatus::ok and byte-exact output on every thread.

Verification

  • g++ -std=c++17 -pthread -Wall -Wextra -Werror -I src tests/startup_inflate_status.cpp -o /tmp/startup_inflate_status && /tmp/startup_inflate_status -> exit 0
  • g++ -std=c++17 -pthread -fsanitize=thread -O1 -g -Wall -Wextra -Werror -I src tests/startup_inflate_status.cpp -o /tmp/startup_inflate_status_tsan && /tmp/startup_inflate_status_tsan -> exit 0
  • git diff --check -> clean
  • python3 tests/docs_links_check.py -> pass
  • python3 tests/bidi_controls_check.py -> pass
  • python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py preflight /root/wt/x2w-h-w3-inflate -> VERDICT: OK

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6582165657 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1488). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T12:49:59Z. --- ## Summary - Fix a multithreaded static-initialization data race in `x2w_inflate::fixed_block` (`src/startup_stubs/inflate.h`). Previously, `fixed_block` guarded non-atomic `static Huffman lencode, distcode` initialization with a non-atomic `static bool ready = false`, allowing concurrent callers to observe `ready == true` before table construction finished or race on initialization. - Replace the racy flag with C++11/17 thread-safe function-local `static const FixedTables tables = make_fixed_tables();` initialization (`[stmt.dcl]/4`), keeping the hot path lock-free and immutable after construction. - Extend `tests/startup_inflate_status.cpp` with a multi-threaded `fixed_lit_stream` stress test (`check_fixed_multithreaded`) that synchronizes 8 `std::thread`s at a start barrier before invoking `inflate_zlib_ex` concurrently, verifying `InflateStatus::ok` and byte-exact output on every thread. ## Verification - `g++ -std=c++17 -pthread -Wall -Wextra -Werror -I src tests/startup_inflate_status.cpp -o /tmp/startup_inflate_status && /tmp/startup_inflate_status` -> exit 0 - `g++ -std=c++17 -pthread -fsanitize=thread -O1 -g -Wall -Wextra -Werror -I src tests/startup_inflate_status.cpp -o /tmp/startup_inflate_status_tsan && /tmp/startup_inflate_status_tsan` -> exit 0 - `git diff --check` -> clean - `python3 tests/docs_links_check.py` -> pass - `python3 tests/bidi_controls_check.py` -> pass - `python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py preflight /root/wt/x2w-h-w3-inflate` -> `VERDICT: OK` AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-24 13:00:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T12:58:18Z.


Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit db7d106ddbf6af26b6c47e8895630129bef29710:

  • Debug (--preset dev): ctest -R '^startup_inflate': 2/2 passed (startup_inflate_status 0.01s, startup_inflate 0.25s)
  • Release /O2 (--preset release): ctest -R '^startup_inflate': 2/2 passed (startup_inflate_status 0.01s, startup_inflate 0.22s)

Linux: g++ -std=c++17 -pthread -Wall -Wextra -Werror clean, repeated runs pass, -fsanitize=thread clean; git diff --check clean.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7132167827 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1488#issuecomment-7132167827). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T12:58:18Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `db7d106ddbf6af26b6c47e8895630129bef29710`: - **Debug (`--preset dev`)**: `ctest -R '^startup_inflate'`: 2/2 passed (`startup_inflate_status` 0.01s, `startup_inflate` 0.25s) - **Release `/O2` (`--preset release`)**: `ctest -R '^startup_inflate'`: 2/2 passed (`startup_inflate_status` 0.01s, `startup_inflate` 0.22s) Linux: `g++ -std=c++17 -pthread -Wall -Wextra -Werror` clean, repeated runs pass, `-fsanitize=thread` clean; `git diff --check` clean. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-24 13:00:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T12:58:29Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T13:01:51.449842Z db7d106 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7132172234 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1488#issuecomment-7132172234). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T12:58:29Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"db7d106ddbf6af26b6c47e8895630129bef29710","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-24T13:01:51.449842Z">2026-11-24T13:01:51.449842Z</relative-time> | `db7d106` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
upstream-sync closed this pull request 2026-11-24 14:02:53 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!1481
No description provided.