Skip to content

Conversation

@rajanyadav0307
Copy link

Issue #, if available:
N/A

Description of changes:
This PR improves the thread-safety and lifetime correctness of ThreadTask.

Changes include:

  • Reordering data members so std::thread is destroyed last, ensuring all
    members accessed by the worker thread remain valid during destruction.
  • Promoting m_detached to std::atomic<bool> to prevent data races when
    accessed concurrently by multiple threads.
  • Updating the constructor initializer list to match the member declaration
    order and using a lambda for thread startup for improved clarity.

These changes do not modify the public API and are purely internal
correctness and safety improvements.

Check all that applies:

  • Did a review by yourself.
  • Added proper tests to cover this PR. (Existing threading behavior is exercised; no new tests required.)
  • Checked if this PR is a breaking (APIs have been changed) change.
  • Checked if this PR will not introduce cross-platform inconsistent behavior.
  • Checked if this PR would require a ReadMe/Wiki update.

Check which platforms you have built SDK on to verify the correctness of this PR.

  • Linux
  • Windows
  • Android
  • MacOS
  • IOS
  • Other Platforms

By submitting this pull request, I confirm that you can use, modify, copy, and
redistribute this contribution, under the terms of your choice.

Change:
Reorder ThreadTask data members so std::thread is destroyed last, ensuring
all members accessed by the running thread remain valid during shutdown.
Also make the detach flag atomic to avoid potential data races between the
executor thread and the owning thread.

Reason:
This change improves thread-safety and prevents subtle undefined behavior
without modifying the public API.
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