Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread creation/destruction callbacks for TaskPool #1991

Closed
farnoy opened this issue Apr 23, 2021 · 0 comments
Closed

Thread creation/destruction callbacks for TaskPool #1991

farnoy opened this issue Apr 23, 2021 · 0 comments
Assignees
Labels
A-Core Common functionality for all bevy apps C-Enhancement A new feature

Comments

@farnoy
Copy link

farnoy commented Apr 23, 2021

What problem does this solve or what need does it fill?

I'd like to be able to run something on each created thread in a TaskPool after it's spawned and before it's destroyed. This would be useful for instrumentation purposes, profilers.

What solution would you like?

I propose adding two new boxed function fields in TaskPoolBuilder to define these operations.

TaskPoolBuilder::new()
    .num_threads(N)
    .thread_name("MyWorker")
    .on_thread_spawn(|ix| { /* executes during build() on each worker */ })
    .on_thread_destroy(|ix| { /* ... */ })
    .build()

What alternative(s) have you considered?

I considered spawning dummy tasks right after creating a TaskPool, but I don't expect to get a stable, round-robin order with each spawned task.

@farnoy farnoy added C-Enhancement A new feature S-Needs-Triage This issue needs to be labelled labels Apr 23, 2021
@alice-i-cecile alice-i-cecile added A-Core Common functionality for all bevy apps and removed S-Needs-Triage This issue needs to be labelled labels Apr 23, 2021
@james7132 james7132 self-assigned this Nov 1, 2022
bors bot pushed a commit that referenced this issue Dec 20, 2022
# Objective
Fix #1991. Allow users to have a bit more control over the creation and finalization of the threads in `TaskPool`.

## Solution
Add new methods to `TaskPoolBuilder` that expose callbacks that are called to initialize and finalize each thread in the `TaskPool`.

Unlike the proposed solution in #1991, the callback is argument-less. If an an identifier is needed, `std::thread::current` should provide that information easily.

Added a unit test to ensure that they're being called correctly.
bors bot pushed a commit that referenced this issue Dec 20, 2022
# Objective
Fix #1991. Allow users to have a bit more control over the creation and finalization of the threads in `TaskPool`.

## Solution
Add new methods to `TaskPoolBuilder` that expose callbacks that are called to initialize and finalize each thread in the `TaskPool`.

Unlike the proposed solution in #1991, the callback is argument-less. If an an identifier is needed, `std::thread::current` should provide that information easily.

Added a unit test to ensure that they're being called correctly.
@bors bors bot closed this as completed in 53a5bbe Dec 20, 2022
alradish pushed a commit to alradish/bevy that referenced this issue Jan 22, 2023
# Objective
Fix bevyengine#1991. Allow users to have a bit more control over the creation and finalization of the threads in `TaskPool`.

## Solution
Add new methods to `TaskPoolBuilder` that expose callbacks that are called to initialize and finalize each thread in the `TaskPool`.

Unlike the proposed solution in bevyengine#1991, the callback is argument-less. If an an identifier is needed, `std::thread::current` should provide that information easily.

Added a unit test to ensure that they're being called correctly.
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
# Objective
Fix bevyengine#1991. Allow users to have a bit more control over the creation and finalization of the threads in `TaskPool`.

## Solution
Add new methods to `TaskPoolBuilder` that expose callbacks that are called to initialize and finalize each thread in the `TaskPool`.

Unlike the proposed solution in bevyengine#1991, the callback is argument-less. If an an identifier is needed, `std::thread::current` should provide that information easily.

Added a unit test to ensure that they're being called correctly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Core Common functionality for all bevy apps C-Enhancement A new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants