Skip to content

executors: Guard against sentinel worker index in thread_pool_scheduler_bulk - #8228

Open
shivansh023023 wants to merge 1 commit into
TheHPXProject:masterfrom
shivansh023023:fix/thread-pool-scheduler-bulk-os-thread
Open

shivansh023023 wants to merge 1 commit into
TheHPXProject:masterfrom
shivansh023023:fix/thread-pool-scheduler-bulk-os-thread

Conversation

@shivansh023023

Copy link
Copy Markdown
Contributor

Proposed Changes

  • Guard against sentinel worker index in thread_pool_scheduler_bulk.hpp: Checks local_worker_thread != static_cast<std::uint32_t>(-1) before calling rp.get_pu_num(local_worker_thread) in detail::bulk_receiver::execute(), falling back to hpx::threads::find_first(op_state->pu_mask) when invoked from a non-HPX OS thread (matching index_queue_spawning_void.hpp).
  • Regression Test: Adds test_bulk_from_os_thread() in libs/core/executors/tests/unit/thread_pool_scheduler.cpp running ex::bulk(ex::thread_pool_scheduler{}, ex::just(42), 10, ...) via tt::sync_wait from a std::thread and verifying the result.

Any background context you want to provide?

When ex::bulk(ex::thread_pool_scheduler{}, ...) is started from a non-HPX OS thread (e.g., a std::thread calling sync_wait), hpx::get_local_worker_thread_num() returns static_cast<std::size_t>(-1) (0xFFFFFFFFu). Previously, detail::bulk_receiver::execute() passed this sentinel directly to rp.get_pu_num(local_worker_thread), causing an assertion failure in Debug builds and an out-of-bounds read / SIGSEGV in Release/RelWithDebInfo builds.

Checklist

  • I have added a new feature and have added tests to go along with it.
  • I have fixed a bug and have added a regression test.
  • I have added a test using random numbers; I have made sure it uses a seed, and that random numbers generated are valid inputs for the tests.

…er_bulk

Signed-off-by: Shivansh Singh <singhshivansh023@gmail.com>
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Fixed bulk operations launched from outside the HPX worker threads so they select a valid processing unit and complete correctly.
    • Added coverage to verify that this execution path returns the expected result.

The bulk sender now selects the first processing unit in its mask when it runs without a valid local worker-thread number. A unit test covers bulk execution from a standard OS thread.

Changes: Bulk sender fallback

Layer / File(s) Summary
Processing-unit fallback and OS-thread test
libs/core/executors/include/hpx/executors/thread_pool_scheduler_bulk.hpp, libs/core/executors/tests/unit/thread_pool_scheduler.cpp
When the local worker-thread number is invalid, execute uses the first processing unit in pu_mask. The test runs the bulk sender from a standard OS thread and checks that the result contains 42 and the sum is 465.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested labels: type: defect, category: executors

Merge Risk: Minimal · up to 1c003

This change stops bulk execution from a non-HPX OS thread from passing an invalid worker index into processing-unit lookup, which previously could assert in Debug builds or read out of bounds in Release builds. The fix is small and localized, and a regression test covers the OS-thread case. No concrete merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the change: a guard against the sentinel worker index in thread_pool_scheduler_bulk. The raw summary and the description confirm that the fix checks for the sentinel and falls back to …
Description check Passed The description states the bug, the fix in detail::bulk_receiver::execute(), and the regression test test_bulk_from_os_thread(). These match the raw summary, which describes the sentinel check and the…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the change: a guard against the sentinel worker index in thread_pool_scheduler_bulk. The raw summary and the description confirm that the fix checks for the sentinel and falls back to the first processing unit in the pu_mask. The title is specific and matches the main change.

Full details: Description check

Explanation

The description states the bug, the fix in detail::bulk_receiver::execute(), and the regression test test_bulk_from_os_thread(). These match the raw summary, which describes the sentinel check and the added test.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8b400207-f1b2-4f6b-a0ca-8715bd415a62
Commits

Reviewing files that changed from the base of the PR and between 88ab4ba and 1c00365.

Files selected for processing: 2

  • libs/core/executors/include/hpx/executors/thread_pool_scheduler_bulk.hpp
  • libs/core/executors/tests/unit/thread_pool_scheduler.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant