Skip to content

Thread creation/destruction callbacks for TaskPool #1991

@farnoy

Description

@farnoy

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.

Metadata

Metadata

Assignees

Labels

C-FeatureA new feature, making something new possible

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions