Skip to content

fix: preserve lvalues in execution queue - #3654

Open
songgaoye wants to merge 2 commits into
apache:masterfrom
songgaoye:fix/execution-queue-perfect-forwarding
Open

songgaoye wants to merge 2 commits into
apache:masterfrom
songgaoye:fix/execution-queue-perfect-forwarding

Conversation

@songgaoye

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: resolve

Problem Summary:

ExecutionQueue<T>::execute(const T&, ...) casts its const lvalue input to
T& and forwards it as T&&. As a result, submitting an lvalue can invoke
T's move constructor and unexpectedly modify the caller's object.

What is changed and the side effects?

Changed:

  • Replace the const_cast-based forwarding path with an internal forwarding
    helper.
  • Preserve copy semantics for lvalue tasks and move semantics for rvalue tasks.
  • Add a regression test verifying that submitting an lvalue does not move from
    it.

Side effects:

  • Lvalue task submissions now consistently copy the task, as implied by the
    const T& API.

  • Rvalue task submissions retain their existing move behavior.

  • Performance effects:

    No expected impact on rvalue submissions. Lvalue submissions now avoid
    unintended moves and follow the intended copy path.

  • Breaking backward compatibility:

    No API or ABI changes. Code that unintentionally relied on an lvalue being
    moved from will observe the corrected behavior.


Check List:

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused forwarding fix preserves the intended submission semantics, and the regression test covers the reported defect with no identified blocking issues.

No open issues 🎉

What changed in this PR

This PR fixes execution queue submission so lvalue tasks are copied without modifying the caller’s object, while rvalue tasks retain move semantics.

Changes:

  • Replace const-cast forwarding with a private helper that preserves value categories.
  • Add a regression test checking that lvalue submission does not move from the original task and produces the expected result.
File Description
test/​bthread_execution_queue_unittest.cpp Add a copy/move-aware task and lvalue regression test.
src/​bthread/​execution_queue_inl.h Preserve copy and move semantics through a forwarding helper.

Review effort: Balanced

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.

2 participants